javascript - React Redux - call dispatch without connect (not from a react component) -
i have scheduled function fetches data server every x minutes , want update state response:
api.fetchdata().then( (response) => { dispatch(actions.updateconfiguration(response)); } };
this function should not react component since doesn't render anything.
however can't seem figure out how inject dispatch
function without using connect
, requires react component.
thanks.
we've similar thing (a recurring check on wether auth token still valid) , did following.
in our little "util" function receive redux store parameter
export function startsessiontimer(store) { const intervalid = setinterval(() => { if ( ... ) { store.dispatch( ... ); clearinterval(intervalid); } }, (15 * 60 * 1000)); }
then, set our app , create store, kick-start timer.
const store = configurestore( ... ); startsessiontimer(store);
Comments
Post a Comment