How to use redux-saga with redux and react-redux -


i trying understand how redux-saga works, implementing simple example (a button when clicked fetch user api , reducer adds user store) react, redux , react-redux.

here saga (with console.logs debugging):

import { take, call, put }  'redux-saga/effects';  import { get_user, setuser } './actions/actioncreators';  export default function * watchfetchuser () {   console.log('inside saga');   yield take(get_user);   console.log('received click');   const url = 'http://uinames.com/api/?ext';   const user = yield call(fetch, url);   const usertojson = yield user.json();   yield  put(setuser(usertojson)) } 

unfortunately when click "get user" button nothing happens:

import react, { proptypes } 'react'; import cssmodules 'react-css-modules';  import styles './button.css';  const button = ({ getuser }) => {   function handleclick() {     getuser     console.log('clicked');   }    return (     <button       type='text'       stylename='button'       onclick={handleclick}     >get user</button>   ) }   button.proptypes = {   getuser: proptypes.func }  export default cssmodules(button, styles, { allowmultiple: true }); 

here whole repo: link repo on github

your problem has nothing sagas. code missing "a glue" between redux , react in form of mapstatetoprops , mapdispatchtoprops. note in app.js using button component without props required trigger get_user action. please take @ redux documentation page.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -