JSFiddle - React, Tailwind, and code Playground
by Farzad YZ
JavaScript
console.clear();
function stateContainer(initialState = {}) {
let state = Object.assign({
set [prop](value) {
console.warn(`You're not supposed to update state with direct assignment, instead, you can use setState`);
}
}, initialState);
return {
getState() {
return state;
},
setState(updater) {
state = Object.assign({}, state, updater(state));
}
}
}
const store = stateContainer({
loading: false
});
/* store.state */