Would it be possible to get a working

Would it be possible to get a working code sample of embedded code in react? My main conundrum is adding an init function with customer user data within the component itself. All of the example I've seen online show the init function outside of the component. I put mine in a useeffect that waits for the user email to load. It works but it's not ideal. I get many refreshes before the embedded window loads. I'm also having inconsistent experiences across different browsers.
11 Replies
Justin Mathew
Justin Mathew15mo ago
@Michael take a look at these sandboxes we have : https://codesandbox.io/s/big-tse-react-demo-forked-wl5vq4?file=/src/App.tsx simpler one : https://codesandbox.io/s/authmethod-testing-m8l3cm?file=/src/App.tsx ideally the flow should be that init runs only once , and the components should be rendered only after that
Michael
MichaelOP15mo ago
You have the init running in App.tsx. How can I get the username and other user details into this?
suhel4code
suhel4code15mo ago
We have an api for getting current user info In your cluster rest-api-playgroundv2 /api/rest/2.0/auth/session/user
suhel4code
suhel4code15mo ago
No description
ashish
ashish15mo ago
@Michael can you post a snippet of your current code? init inside the the useEffect should still work as long as it is called once for the lifetime of an app load.
Michael
MichaelOP15mo ago
The user is created using the init function. I could create the user through the API but I already have that working through init. Feels safer to me than using an api to figure out what's going on as the user is trying to render the home page. If I don't init outside of the module it will crash the site. Do you want me to post the whole component in this chat? I'll assume you want the file and not the whole thing pasted into chat
Michael
MichaelOP15mo ago
Just checking in. I need the embedded application working, it's the most important feature for us.
ashish
ashish15mo ago
Sorry, missed the code. I see you are calling init twice. We can just call it inside the useEffect that should be okay. And we should try to render the liveboard only after the init is called.
ashish
ashish15mo ago
https://codesandbox.io/s/big-tse-react-demo-forked-wlv9z9?file=/src/App.tsx .. here is a code sample that has the init in a useEffect
ashubham
CodeSandbox
Big TSE React Demo (forked) - CodeSandbox
Big TSE React Demo (forked) by ashubham using @inovua/reactdatagrid-enterprise, @kanaries/graphic-walker, @thoughtspot/rest-api-sdk, @thoughtspot/visual-embed-sdk, antd, lodash, prop-types, react, react-dom
Michael
MichaelOP15mo ago
This was very helpful. I made the addition of wrapping the state variable in an event emitter and it works beautifully. So far it looks great on every browser I've tested so far.

Did you find this page helpful?