This commit is contained in:
Tomas Dvorak
2026-02-24 10:33:59 +01:00
parent 409acd2e08
commit 898a3c303f
1374 changed files with 290409 additions and 29187 deletions
+17
View File
@@ -0,0 +1,17 @@
{
"id": "905c9844113db2c200d4f3c2",
"source": "solid:signals",
"type": "github-document",
"title": "create-store",
"content": "---\ntitle: createStore\nuse_cases: \u003e-\n complex state management, nested data, arrays and objects, derived values,\n application state\ntags:\n - store\n - state\n - data-structures\n - objects\n - arrays\nversion: '1.0'\ndescription: \u003e-\n Manage complex application state with createStore. Handle nested objects,\n arrays, and derived values with fine-grained reactivity.\n---\n\nStores were intentionally designed to manage data structures like objects and arrays but are capable of handling other data types, such as strings and numbers.\n\n## Types Signature\n\n```tsx\nimport { createStore } from \"solid-js/store\"\nimport type { StoreNode, Store, SetStoreFunction } from \"solid-js/store\"\n\nfunction createStore\u003cT extends StoreNode\u003e(\n\tstate: T | Store\u003cT\u003e\n): [get: Store\u003cT\u003e, set: SetStoreFunction\u003cT\u003e];\n\ntype Store\u003cT\u003e = T; // conceptually readonly, but not typed as such\n```\n\n## Usage\n\n```tsx\nimport { createStore } from \"solid-js/store\";\n\n// Initialize store\nconst [store, setStore] = createStore({\n\tuserCount: 3,\n\tusers: [\n\t\t{\n\t\t\tid: 0,\n\t\t\tusername: \"felix909\",\n\t\t\tlocation: \"England\",\n\t\t\tloggedIn: false,\n\t\t},\n\t\t{\n\t\t\tid: 1,\n\t\t\tusername: \"tracy634\",\n\t\t\tlocation: \"Canada\",\n\t\t\tloggedIn: true,\n\t\t},\n\t\t{\n\t\t\tid: 1,\n\t\t\tusername: \"johny123\",\n\t\t\tlocation: \"India\",\n\t\t\tloggedIn: true,\n\t\t},\n\t],\n});\n```\n\n## Getter\n\nStore objects support the use of getters to store derived values.\n\n```tsx\nconst [state, setState] = createStore({\n\tuser: {\n\t\tfirstName: \"John\",\n\t\tlastName: \"Smith\",\n\t\tget fullName() {\n\t\t\treturn `${this.firstName} ${this.lastName}`;\n\t\t},\n\t},\n});\n```\n\n## Setter\n\nChanges can take the form of function that passes previous state and returns new state or a value.\nObjects are always shallowly merged. Set values to undefined to delete them from the Store.\nIn TypeScript, you can delete a value by using a non-null assertion, like `undefined!`.\n\n```tsx\nconst [state, setState] = createStore({\n\tfirstName: \"John\",\n\tlastName: \"Miller\",\n});\n\nsetState({ firstName: \"Johnny\", middleName: \"Lee\" });\n// ({ firstName: 'Johnny', middleName: 'Lee', lastName: 'Miller' })\n\nsetState((state) =\u003e ({ preferredName: state.firstName, lastName: \"Milner\" }));\n// ({ firstName: 'Johnny', preferredName: 'Johnny', middleName: 'Lee', lastName: 'Milner' })\n```\n\n---\n\nTo learn more about using stores check the [Stores Guide](/concepts/stores), and the **Store utilities** section for more advanced APIs.",
"url": "https://github.com/solidjs/solid-docs/blob/HEAD/src/routes/reference/store-utilities/create-store.mdx",
"metadata": {
"path": "src/routes/reference/store-utilities/create-store.mdx",
"repo": "solidjs/solid-docs",
"repo_url": "https://github.com/solidjs/solid-docs.git",
"size": 2372,
"source_type": "github"
},
"hash": "a32e10cac95180d2c45e2f2fd487cec2da9db69f23b426e9bfdc0d8dbfec7a3e",
"timestamp": "2026-02-23T11:43:00.190822298+01:00"
}