await set
#804
Replies: 2 comments 3 replies
-
Can you provide a small code snippet? |
Beta Was this translation helpful? Give feedback.
0 replies
-
yes i made one solution but i think it is not a goot idea. const forceAwait = async (get: () => any, name: string, value: any) =>
new Promise((resolve) => {
let data: any;
do {
data = get()[name];
if (data === value) resolve(true);
} while (data !== value);
});
//IMPLEMENTATION
const useRodneyDataStore = create<RodneyBroadcastContextDataStore>(
(set, get) => ({
data: null,
setData: async (value, callback) => {
set({ data: value });
await forceAwait(get, 'data', value);
if (callback) await callback(get().data);
},
})
);
// now i can use this
setData: useRodneyDataStore((state) => state.setData),
await setData('xyz')
// or
setData('xyz', async()=>{
// dothis
}) |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
how can i await to chage value when ai use action to set value?
Beta Was this translation helpful? Give feedback.
All reactions