UI developer tutorials and guides

Friday, June 24, 2022

Create a simple store in Solidjs

 Stores are way to distribute collected data among components. In Vuejs Vuex (default) and Pinia stands for stores and for React, you have to choose one like Redux.

Solidjs provides inbuilt store. There are two way to create a store, create a store using createStore method or create a mutable store using createMutable.

A mutable store allow us to directly access and modify data, no need for getters and setters. We goes this way. ➡ 

Create Store

Create a store and export it, so that rest of the modules can access it.

export const store = createMutable({ myText: "" });

 Accessing in component

The component can be accessed and modified using as regular JavaScript objects.

import store from './store'

console.log(store.myText)

Read more about Mutable store


0 comments:

Post a Comment