-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"New" button for all users & global state management discussion #791
Comments
I made new button available to all users here: #823 I looked at triggering add layer panel but it was more difficult than expected because the state of whether or not the add layer panel is open is in another component (main component?) and not the toolbar component. Maybe revisit after redux? |
Yes you have a state It's been years since I used About the trends, I see the react community on X and YouTube uses solutions like I personally used Here is an example: in atom.js import { atom, createStore } from "jotai";
export const jotaiStore = createStore();
export const micEnabledAtom = atom(true);
export const getMicEnabled = (): boolean => {
return jotaiStore.get(micEnabledAtom);
};
export const setMicEnabled = (enabled: boolean) => {
jotaiStore.set(micEnabledAtom, enabled);
}; in index.js import { Provider as JotaiProvider } from "jotai";
<JotaiProvider store={jotaiStore}>
<App />
</JotaiProvider> in MicButton.js export const MicButton = () => {
const [micEnabled, setMicEnabled] = useAtom(micEnabledAtom);
...
} If you don't need the setter, simply: const isBotEnabled = useAtomValue(isBotEnabledAtom); in some callback: cameraRig.setAttribute("player-info", {
muted: !getMicEnabled(),
name: name,
}); |
Also note that we are using in this project for example
as a way to access the state setter, registering a listener just for that 3dstreet/src/editor/components/Main.js Lines 139 to 142 in afb7aa2
What would be more familiar to a react developer is defining a setter setGeoModalOpened = (open) => {
posthog.capture('geo_modal_opened');
this.setState({isGeoModalOpened: true});
} and pass setGeoModalOpened as prop to GeoModal component. With jotai, that could be rewritten like this: in GeoModal.js: const setGeoModalOpened = useSetAtom(geoModalOpenedAtom)
const onClick = () => {
setOpenGeoModal(true);
}; in Main.js: const isGeoModalOpened = useAtomValue(geoModalOpenedAtom) in atom.js: export const geoModalOpenedAtom = atom(false) |
im open to using zustand, it seems like it's a popular library with decent integrations. Regardless of choice, global state management would be really good. So, if we're in agreement w/ zustand, let's go ahead and start adding it into the project! |
closed by #823 new tickets based on discussion: |
I'm okay with zustand with the simplest form. I just want to avoid the reducers and actions, I have PTSD with those. :'D |
The text was updated successfully, but these errors were encountered: