1.0.0 • Published 4 years ago

svelte-usereducer v1.0.0

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

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);
})