iam really in trouble with this hook iam kinda new i searched watched lot of videos on youtube also visit most of the blog site but didnt found the solution
here is the code
id : string;
created_at? : FieldValue;
data : LinkItemScheme[] | [];
}```
`const [sections, setSections] = useState<SectionScheme[]>(STATIC_SECTION_DATA);
const [optimisticSections, updateOptimisticSections] = useOptimistic<SectionScheme[], SectionScheme>(
sections,
(currentState, updatedSection) => {
return [...currentState, updatedSection];
}
);
const CreateSection = async (section : SectionScheme) => {
const regex = /[-\/()[\];+\-^*]/;
if(section.id.length > 3) {
const newSection: SectionScheme = { ...section };
updateOptimisticSections(newSection);
}
else {
alert('Please Enter Section Name With Least 3 Character Long');
}
console.log('Creating new section in db... ', regex.test(section.id));
}`
the problem here is when the CreateSection function get called the updateOptimisticSections create the new section for blink of an eye then revert back