I'm using redux saga on a react-boilerplate open source project on github and I'm using redux saga to delete users. The code works perfectly on a create-react-app but doesn't work on the react-boilerplate (https://github.com/yarusophialiu/react-boilerplate/blob/master/app/containers/HomePage/saga.js). The thing is that the yield take(...)
returns null. I console.log action.js and found that an action is dispatched when I click delete. Any help would be appreciated!!!
HomePage/saga.js
export function* deleteUser({ userId }) {
try {
yield call(api.deleteUser, userId);
// yield call(getUsers);
} catch (e) {
console.log(e);
}
}
export function* watchDeleteUserRequest() {
// yield takeLatest(DELETE_USER_REQUEST, getRepos);
while (true) {
const action = yield take(DELETE_USER_REQUEST);
yield call(deleteUser, {
userId: action.payload.userId,
});
}
}
HomePage actions.js
export const deleteUserRequest = userId => ({
type: DELETE_USER_REQUEST,
payload: {
userId,
},
});
HomePage/index.js
...
import { createStructuredSelector } from 'reselect';
import { useInjectReducer } from 'utils/injectReducer';
import { useInjectSaga } from 'utils/injectSaga';
import { changeUsername, deleteUserRequest } from './actions';
import reducer from './reducer';
import saga from './saga';
import UserList from '../UsersPage/UserList';
const key = 'home';
export function HomePage({
username,
loading,
error,
repos,
onSubmitForm,
onChangeUsername,
}) {
useInjectReducer({ key, reducer });
console.log('home', saga);
useInjectSaga({ key, saga });
const [users, setUsers] = useState([]);
useEffect(() => {
axios
.get('https://rem-rest-api.herokuapp.com/api/users', {
params: {
limit: 1000,
},
})
.then(({ data }) => {
setUsers(data.data);
});
}, []);
const handleDeleteUserClick = userId => {
console.log('delete', deleteUserRequest(userId));
deleteUserRequest(userId);
};
const reposListProps = {
loading,
error,
repos,
};
return (
<article>
<div>
<UserList users={users} onDeleteUser={handleDeleteUserClick} />
</div>
</article>
);
}
...