Avoid Error: Calling setState synchronously within an effect can trigger cascading renders
Unanswered
Forest bachac posted this in #help-forum
Forest bachacOP
Here is my implementation, is there a better way to do this:
Is the correct way to create a child component with a key
const supabase = createClient();
const {
data: user,
error,
isLoading,
mutate,
} = useSWR("user", async () => fetcher(supabase, uid));
const [email, setEmail] = useState("");
const [fullname, setFullname] = useState("");
useDirty(email !== user?.email || fullname !== user?.fullname);
useEffect(() => {
if (!user) return;
setEmail(user?.email);
setFullname(user?.fullname);
}, [user]);Is the correct way to create a child component with a key
1 Reply
You don’t need an effect for this.
SWR will keep your user data up to date, and always in sync as long as the SWR key contains all the data used in the request. Add
Also, what are you trying to achieve?
Do you pass the data down to a component that renders the user data?
SWR will keep your user data up to date, and always in sync as long as the SWR key contains all the data used in the request. Add
uid to the keyAlso, what are you trying to achieve?
Do you pass the data down to a component that renders the user data?