| 151 | * @since 4.0.0 |
| 152 | */ |
| 153 | export const useAtomSet = < |
| 154 | R, |
| 155 | W, |
| 156 | Mode extends "value" | "promise" | "promiseExit" = never |
| 157 | >( |
| 158 | atom: () => Atom.Writable<R, W>, |
| 159 | options?: { |
| 160 | readonly mode?: ([R] extends [AsyncResult.AsyncResult<any, any>] ? Mode : "value") | undefined |
| 161 | } |
| 162 | ): "promise" extends Mode ? ( |
| 163 | (value: W) => Promise<AsyncResult.AsyncResult.Success<R>> |
| 164 | ) : |
| 165 | "promiseExit" extends Mode ? ( |
| 166 | (value: W) => Promise<Exit.Exit<AsyncResult.AsyncResult.Success<R>, AsyncResult.AsyncResult.Failure<R>>> |
| 167 | ) : |
| 168 | ((value: W | ((value: R) => W)) => void) => |
| 169 | { |
| 170 | const registry = useContext(RegistryContext) |
| 171 | mountAtom(registry, atom) |
| 172 | return setAtom(registry, atom, options) |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Mounts an atom and returns a callback that refreshes the current atom. |