Reputation: 323
I'm using ReactQuill in my project. pretty newbie using react-quill. I'm using react and nextjs in my project. so I imported react-quill dynamically for preventing server side rendering:-
const ReactQuill = dynamic(() => import("react-quill"), { ssr: false });
in my component I'm using ReactQuill without any additional settings.
const MyComponent = () => {
//handleSingleChange method is defined here
//formData here
//and any other methods, states
return (
<>
<ReactQuill
value={formData?.company_page?.about || ""}
onChange={(e) => handleSingleChange("about", e)}
/>
</>
)
}
I've discovered few scenarios:
It will be kind if anybody could help to solve this issue.
Upvotes: 0
Views: 1177
Reputation: 323
in the method handleSingleChange, I was trying to update to state.
const handleSingleChange = (name, value) => {
setCompanyPage({...companyPage, [name]: value})
setFormData({...formData, company_page:companyPage})
};
as I was trying to update the companyPage state immediately, it was not working, bCoz in react, state doesn't update immediately.
So I had to take a variable in which I override the companyPage state and later updated it in formData. see below method.
const handleQuillChange = (name, value) => {
const updatedCompanyPage = {...companyPage, [name]: value};
setFormData({...formData, company_page: updatedCompanyPage})
}
Upvotes: 0