newfold-labs / wp-module-ecommerce

Next-generation eCommerce Experience for WordPress sites at Newfold Digital.
GNU General Public License v2.0
9 stars 3 forks source link

JS Error in v1.3.13 #185

Closed circlecube closed 10 months ago

circlecube commented 10 months ago

Seeing a JS error which breaks the React app. It states

Warning: useEffect must not return anything besides a function, which is used for clean-up.

It looks like you wrote useEffect(async () => ...) or returned a Promise. Instead, write the async function inside your effect and call it immediately:

useEffect(() => {
  async function fetchData() {
    // You can await here
    const response = await MyAPI.getData(someId);
    // ...
  }
  fetchData();
}, [someId]); // Or [] if effect doesn't need props or state

I believe I've pinpointed it to this line which was included in v1.3.13:

useEffect(async () => {
    const data = await useThumbnail(NewfoldRuntime.homeUrl);
    setThumbnail(data?.thumbnail_loc);
}, []);

See: https://github.com/newfold-labs/wp-module-ecommerce/blob/trunk/src/components/OnboardingScreen.js#L52-L55 & https://github.com/newfold-labs/wp-module-ecommerce/compare/v1.3.12...v1.3.13#diff-fd672c79443c2dc41c55d1d45484f87c38f677499a7a938d75860dc61b947270R52-R55

circlecube commented 10 months ago

Fixed in v1.3.14