Functions inside store VS outside store?

I want to know what best practice is. I watched some solid youtube tutorials.. Some people put their functions 'get' , 'set' , or 'doSomething' inside store, What's common way???
5 Replies
fabiospampinato
It depends on what you want to do, all those are fine do you want to call the function or access the function and call it implicitly?
musiclover
musicloverOP3y ago
Do you use both pattern then?
fabiospampinato
I don't use either of them, I don't put functions in stores, I use stores for data only basically
musiclover
musicloverOP3y ago
Don't you need any functions to mutate store? Do you use signal?
REEEEE
REEEEE3y ago
You have the functions outside the store
const [store, setStore] = createStore({
data: 1,
mySeconData: 4
})

const updateData = (newDataValue: number) => {
setStore('data', newDataValue)
}
const [store, setStore] = createStore({
data: 1,
mySeconData: 4
})

const updateData = (newDataValue: number) => {
setStore('data', newDataValue)
}
use the setStore function to update the store

Did you find this page helpful?