svelte-usereducer
v1.0.0
Published
useReducer hook for Svelte
Downloads
1
Readme
Svelte's useReducer
Use the useReducer
hook :)
// reducers.js
import { combineReducers } from 'svelte-usereducer'
import room from './room';
import me from './me';
import producers from './producers';
export default combineReducers({
room,
me,
producers,
});
// index.js
import { onMount, setContext } from 'svelte';
import { useReducer } from 'svelte-usereducer'
import reducer from './reducers.js'
const initialState = {
// ...
}
const initialFunc = () => {};
const [state, dispatch] = useReducer(reducer, initialState); // or useReducer(reducer, initialState, initialFunc);
// if You want to use it as context
setContext("store", {
state,
dispatch
})
// example usage
onMount(() => {
console.dir($state);
})