recoil#useRecoilCallback JavaScript Examples
The following examples show how to use
recoil#useRecoilCallback.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: hooks.js From recoil-paint with MIT License | 5 votes |
export function useUpdateItem() {
return useRecoilCallback(({set}) => async (newValue) => {
set(itemWithId(newValue.id), newValue)
});
}
Example #2
Source File: hooks.js From recoil-paint with MIT License | 5 votes |
export function useNewItem() {
return useRecoilCallback(({snapshot: {getPromise}}) => async (shapeParam) => {
let id = createNewShape(shapeParam);
const item = await getPromise(itemWithId(id));
return item;
});
}
Example #3
Source File: hooks.js From recoil-paint with MIT License | 5 votes |
export function useLoadItems() {
return useRecoilCallback(({snapshot: {getPromise}}) => async (itemIds) => {
return await Promise.all(
itemIds.map(id => getPromise(itemWithId(id)))
);
}, []);
}
Example #4
Source File: hooks.js From recoil-paint with MIT License | 5 votes |
export function useUpdateItems() {
return useRecoilCallback(({set}) => async (newValue) => {
newValue.forEach(item => {
set(itemWithId(item.id), item);
})
}, []);
}