redux-thunk

Where to put business logic in redux? action or store

你说的曾经没有我的故事 提交于 2019-12-09 08:49:13
问题 i come from Reflux to Redux . in Reflux your business logic is exist only in store but in Redux its seems different..for example in " Redux " i have "async-action" and i implemented it with " redux-thunk " . in one scenario i want to check something in my action and if that needed i send request to server and get some data. i this case i have to check my logic in my action and actually my business logic is exist in action and store together and its not good.. what is your solution? for

how to setstate after saga async request

我是研究僧i 提交于 2019-12-07 09:16:08
问题 I'm using redux-saga in my project. I used redux-thunk before, so i can't setState ends of some async request. like this.props.thunkAsync() .then(){ this.setState({ '' }); } Since thunk returns promise, i could use 'then'. But i can't do this with saga, because saga doesn't return promise. So i did it in componentWillReceiveProps by checking flag props (like REQUEST_SUCCESS,REQUEST_WAITING...) has been changed. I think it's not good way to solve this problem. So.. My question is how can i do

how to `bindActionCreators` with redux-thunk

▼魔方 西西 提交于 2019-12-07 06:47:48
问题 I am quite new to JavaScript and react-native and I have existing project that I need to add functionality to. It is using redux and redux-thunk with redux-saga to send API requests. Currently it supports only 1 dispatch function per component and I need to dispatch several types of requests to the saga. I am trying to bindActionCreators to add the dispatch to the stores but to no avail.. I am totally lost on the mapDispatchToProps part and how do I "fire the action" afterwards.. in single

Getting a ID back from a reducer in redux

假如想象 提交于 2019-12-07 05:35:50
问题 I'm fairly new and trying to build a simple bookmark application with react & redux. I can't spin my head around this problem: A user can create one bookmark and add it to multiple folders . So I dispatch an addMark(bookmark) action, and after that addMark(folder) or editFolder(folder) if the folder already exists. As you can see, bookmark and folder are added via the same action, because in my state tree they are both just marks - distinguished by their type property. My problem: How can I

How should I use “redux-thunk” for Async Initial state ? (react/redux)

≡放荡痞女 提交于 2019-12-07 04:49:40
问题 This question have already been ask several time, however I didn't really understand the answers I found. Using React/Redux, I'm trying to get async data into my initial state with express. Since I'm used to d3 one of my option was to use "d3.json"... but I would be happy to use something else if it's better. From a previous answers on the same topic I add the following code : // redux action using a dispatcher (think middleware) export function cool(url) { return function(dispatch) { return

Redux-thunk: `dispatch is not a function`

半城伤御伤魂 提交于 2019-12-06 15:12:37
So, I'm having an issue with an action returning the above mentioned error (See attached image), instead of updating redux state as expected. What am I overlooking here? actionCreators.js export function userToken(token) { console.log('userToken has been fired'); return (dispatch) => { dispatch({ type: 'Graphcool_Token', payload: token }); } } App.js .... // Root Query const allPostsCommentsQuery = graphql(All_Posts_Comments_Query, { options: { cachePolicy: 'offline-critical', fetchPolicy: 'cache-first', }, }); export const mapDispatchToProps = (dispatch) => { return bindActionCreators

Firebase, react and redux wait for store to update

你离开我真会死。 提交于 2019-12-06 13:16:38
问题 I have a React app connected to Firebase, i want to check if user is logged in at every page refresh, dispatching IS_SIGNED_IN action, here's the action creator: export function checkAuth() { return dispatch => { firebaseAuth().onAuthStateChanged((user) => { if (user) { dispatch(signedInAction()) } else { dispatch(signedOutAction()) } }) } } Inside the reducer i just make boolean isAuthenticated to true/false: case ActionTypes.isSignedIn: { return Object.assign({}, state, { isAuthenticated:

Perform Ajax Fetch in a Redux Reducer?

守給你的承諾、 提交于 2019-12-06 03:20:20
I'm trying to wrap my head around accessing the state inside Redux actionCreators; instead did the following (performed ajax operation in the reducer). Why do I need to access the state for this — because I want to perform ajax with a CSRF token stored in the state. Could someone please tell me if the following is considered bad practice/anti-pattern? export const reducer = (state = {} , action = {}) => { case DELETE_COMMENT: { // back-end ops const formData = new FormData(); formData.append('csrf' , state.csrfToken); fetch('/delete-comment/' + action.commentId , { credentials:'include' ,

Getting a ID back from a reducer in redux

纵饮孤独 提交于 2019-12-05 09:39:27
I'm fairly new and trying to build a simple bookmark application with react & redux. I can't spin my head around this problem: A user can create one bookmark and add it to multiple folders . So I dispatch an addMark(bookmark) action, and after that addMark(folder) or editFolder(folder) if the folder already exists. As you can see, bookmark and folder are added via the same action, because in my state tree they are both just marks - distinguished by their type property. My problem: How can I tell the folder-objects which is the new bookmark to add to folders list of bookmarks? How can I

Is using getState in a Redux Thunk good practice?

不问归期 提交于 2019-12-05 09:17:36
问题 I have seen conflicting (or just confusing, to me) answers in other questions here regarding whether using getState within an action is acceptable, or not, and I have seen quite a few times it being called an anti-pattern. For me, it seems to work great but what is the best practice for doing this if we are not to use getState ? I am using getState within a thunk to filter through an array of users that is currently connected to some mock data and being pulled into the state of the