mirror of
https://github.com/Dvorinka/Devour.git
synced 2026-06-04 04:23:02 +00:00
17 lines
1.7 KiB
JSON
17 lines
1.7 KiB
JSON
{
|
|
"id": "67981896ec63617a429becd3",
|
|
"source": "solid:signals",
|
|
"type": "github-document",
|
|
"title": "create-reaction",
|
|
"content": "---\ntitle: createReaction\nuse_cases: \u003e-\n custom tracking logic, one-time reactions, separating tracking from execution,\n advanced reactive patterns\ntags:\n - reactivity\n - tracking\n - custom\n - effects\n - advanced\nversion: '1.0'\ndescription: \u003e-\n Separate tracking from execution with createReaction. Create one-time reactive\n side effects that run on first dependency change only.\n---\n\n```ts\nimport { createReaction } from \"solid-js\"\n\nfunction createReaction(onInvalidate: () =\u003e void): (fn: () =\u003e void) =\u003e void\n\n```\n\nSometimes it is useful to separate tracking from re-execution.\nThis primitive registers a side effect that is run the first time the expression wrapped by the returned tracking function is notified of a change.\n\n```ts\nconst [s, set] = createSignal(\"start\")\n\nconst track = createReaction(() =\u003e console.log(\"something\"))\n\n// run the reaction next time `s` changes.\ntrack(() =\u003e s())\n\nset(\"end\") // \"something\"\n\nset(\"final\") // no-op since the reaction only runs on the first update, need to call `track` again.\n```",
|
|
"url": "https://github.com/solidjs/solid-docs/blob/HEAD/src/routes/reference/secondary-primitives/create-reaction.mdx",
|
|
"metadata": {
|
|
"path": "src/routes/reference/secondary-primitives/create-reaction.mdx",
|
|
"repo": "solidjs/solid-docs",
|
|
"repo_url": "https://github.com/solidjs/solid-docs.git",
|
|
"size": 1038,
|
|
"source_type": "github"
|
|
},
|
|
"hash": "ff59d24e0a0ccc5d54212062e0a36b8d5596c3eff156830c38bab4f890891d35",
|
|
"timestamp": "2026-02-23T11:43:00.19060486+01:00"
|
|
} |