I'm working on refactoring existing logic into suspense.
These days, I use suspense, but there are many times when I have questions.
const Duplicate = ({ children }) => {
return <section>{children}</section>
};
const Component = () => {
const { data } = useQuery('fetch/any', fetcher, { suspense: true });
return (
<div>
<Button disabled={data.disabled} label="example" />
<Duplicate>{data.name}</Duplicate>
</div>
);
};
const Loading = () => {
return (
<>
<Button disabled label="example" />
<Duplicate>Loading..</Duplicate>
</>
);
};
const Render = () => {
return (
<Suspense fallback={<Loading />}>
<Component />
</Suspense>
);
}
If I write like this, I have to write Button, Duplicate component twice.
Whenever I do this, is this really efficient logic? have a doubt.
In this case, I wonder if it is better not to use suspense, or if there is another way to
bypass it.