TryCatchLearn / Reactivities-v6

313 stars 179 forks source link

Possible issue on ActivityForm when loading /create-activity from page load rather than navigating through app. #2

Closed juzzbott closed 3 years ago

juzzbott commented 3 years ago

I'm only up to the end of section 8 - Routing, however I've found an issue when going to the /create-activity route from the initial page load, rather than being redirected from another route.

The issue is that the 'Loading' screen stays for ever, and doesn't go away. The fix seems pretty simple, all we need to do is set the loadingInitial = false if there is no id.

In the ActivityForm.tsx file, make the following change to the useEffect hook and the *activityStore deconstructor:

const {createActvity, updateActivity, loading, loadActivity, loadingInitial, setLoadingInitial} = activityStore;

...

useEffect(() => {
        if (id) {
            loadActivity(id).then(activity => setActivity(activity!));
        } else {
            setLoadingInitial(false);
        }
    }, [id, loadActivity, setLoadingInitial])

As mentioned initially, I have't actually finished the course yet, so if this is picked up and fixed in a later section, then happy days, however looking the source files on git, this doesn't seem to be immediately apparent.

Great course so far!

Cheers, Justin

juzzbott commented 3 years ago

This is fixed in a later video by setting the loadingInitial = false; in the ActivityForm.tsx module.