FDK v9 with ReactJs

Hello!
Can someone tell me how to get the Client inside the React app with using FDK version 9 ?
The old way used to work in this way :

Regards,
Nasir

1 Like

Hi @Nasir_Haidari ,

You can use something like this:

const App = () => {

  const [loaded, setLoaded] = useState(false);
  const [child, setChild] = useState(<h3>App is loading</h3>)

  useLayoutEffect(() => {
    const script = document.createElement('script');
    script.src = '{{{appclient}}}';
    script.addEventListener('load', () => setLoaded(true));
    script.defer = true;
    document.head.appendChild(script);
  }, []);

  useLayoutEffect(() => {
    if (!loaded) return
    app.initialized().then((client) => {
      setChild((<HelloUser client={client} />))
    })
  }, [loaded])

  return (
    <div>
      {child}
    </div>
  )
}

Please let us know if you face any issues.

Also, note the use of useLayoutEffect instead of useEffect.

Thanks!

4 Likes

Hey @Asif !

It works perfectly! :star_struck:

Thanks for the reply!

1 Like

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.