-
I am using class Foo {
flyAtom = atom('some value');
}
class Bar {
foo: null | Foo = null;
async initialize() {
// do something
this.foo = new Foo();
}
} In this case, I cannot call const bar = new Bar();
// in component:
const fly = useAtomValue(bar.foo?.flyAtom); // does not work, bar.foo is null initially A workaround I can think of: const DEFAULT_FLY_ATOM = atom(null);
// in component:
const fly = useAtomValue(bar.foo?.flyAtom ?? DEFAULT_FLY_ATOM); This workaround works well to me. However I still would like to know if there is a better solution in my situation. |
Beta Was this translation helpful? Give feedback.
Answered by
dai-shi
Dec 17, 2024
Replies: 1 comment 1 reply
-
If it works, it looks okay. Note that it's not reactive to |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
fenprace
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If it works, it looks okay. Note that it's not reactive to
initialize()
.