| 207 | * @since 4.0.0 |
| 208 | */ |
| 209 | export const useAtomSet = < |
| 210 | R, |
| 211 | W, |
| 212 | Mode extends "value" | "promise" | "promiseExit" = never |
| 213 | >( |
| 214 | atom: Atom.Writable<R, W>, |
| 215 | options?: { |
| 216 | readonly mode?: ([R] extends [AsyncResult.AsyncResult<any, any>] ? Mode : "value") | undefined |
| 217 | } |
| 218 | ): "promise" extends Mode ? ( |
| 219 | (value: W) => Promise<AsyncResult.AsyncResult.Success<R>> |
| 220 | ) : |
| 221 | "promiseExit" extends Mode ? ( |
| 222 | (value: W) => Promise<Exit.Exit<AsyncResult.AsyncResult.Success<R>, AsyncResult.AsyncResult.Failure<R>>> |
| 223 | ) : |
| 224 | ((value: W | ((value: R) => W)) => void) => |
| 225 | { |
| 226 | const registry = React.useContext(RegistryContext) |
| 227 | mountAtom(registry, atom) |
| 228 | return setAtom(registry, atom, options) |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Mounts an atom and returns a callback that refreshes it in the current React |