Skip to content

Commit

Permalink
fix: replace mounted with busy state
Browse files Browse the repository at this point in the history
this bug was hiding the ckeditor
  • Loading branch information
AliKdhim87 committed Nov 22, 2022
1 parent 4eec733 commit d11d184
Showing 1 changed file with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@ const Wrapper = styled(Box)`
}
}
`;
let mounted = false
function Editor({ onChange, name, value, disabled }) {
const [productPrice, setProductPrice] = React.useState([]);
const [editor, setEditor] = React.useState([]);
const [priceValue, setPriceValue] = React.useState('');
const [busy, setBusy] = React.useState(false)
// const urlSearchParams = new URLSearchParams(window.location.search);
// const params = Object.fromEntries(urlSearchParams.entries());
// const languageContent = params["plugins[i18n][locale]"];
const { id: pageId } = useParams()


const configuration = {
toolbar: [
"heading",
Expand Down Expand Up @@ -151,6 +150,7 @@ function Editor({ onChange, name, value, disabled }) {
const fetchProductPrice = async () => {

try {
setBusy(true)
const res = await fetch(STRAPI_BACKEND_URL, {
method: "POST",
headers: {
Expand Down Expand Up @@ -184,19 +184,16 @@ function Editor({ onChange, name, value, disabled }) {
const { data } = await res.json();

setProductPrice(data.product.data?.attributes?.price?.data?.attributes || []);
setBusy(false)
} catch (error) {

console.log(error);
setBusy(false)
}
};

React.useEffect(() => {
mounted = true
fetchProductPrice();
return () => {
mounted = false
}
}, []);

}, [pageId]);
return (
<>
<ProductPriceList onChange={(id) => {
Expand All @@ -211,7 +208,7 @@ function Editor({ onChange, name, value, disabled }) {
selectedValue={priceValue}
/>
<Wrapper className={["utrecht-theme", "utrecht-html"].join(" ")}>
{mounted && <CKEditor
{!busy && <CKEditor
editor={ClassicEditor}
disabled={disabled}
config={configuration}
Expand Down

0 comments on commit d11d184

Please sign in to comment.