How to properly use atomWithBroadcast
?
#3083
Unanswered
paulineramos
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm pretty new to
jotai
and I'm having some issues using atomWithBroadcast.The project I'm working on is for an embedded iframe. There's some vanilla js with a
initialize
function that creates the main iframe. From there we can open a modal that is actually a second iframe because it needs to take over the whole screen. Both themain
andmodal
iframes load different routes from the same React application.I can get the
atomWithBroadcast
to work if I'm only reading/writing values in one of the iframes, but when I set a value in themain
iframe and try to read it in themodal
iframe, theatom
is re-initialized so it's always reset.The current example is really simple and only has one component with a
count
. What is the best way to initializeconst broadAtom = atomWithBroadcast('params', {})
in a way that it can be used in both iframes?Is there a way to make both
iframes
talk with each other? Should I just haveconst broadAtom = atomWithBroadcast('params', {})
in a separate file and import this variable in both iframes? I currently have this working withatomWithStorage
but the team is looking into using theatomWithBroadcast
more.Thank you
Beta Was this translation helpful? Give feedback.
All reactions