redux-thunk

React native router flux: TypeError: undefined is not a function (evaluating 'addListener')

帅比萌擦擦* 提交于 2019-12-03 20:13:31
Im working on a react native app using this principal dependencies: react native react native router flux react thunk expo I was working using this package.json: "dependencies": { "expo": "23.0.4", "humps": "^2.0.0", "install": "^0.10.1", "lodash": "^4.17.4", "native-base": "^2.3.5", "react": "16.0.0", "react-native": "0.50.4", "react-native-extend-indicator": "^0.1.2", "react-native-keyboard-aware-scroll-view": "^0.4.2", "react-native-maps": "^0.19.0", "react-native-maps-directions": "^1.3.0", "react-native-modal-datetime-picker": "^4.13.0", "react-native-qrcode": "^0.2.6", "react-native

Why use Redux Thunk [closed]

拜拜、爱过 提交于 2019-12-03 13:06:52
Why use Redux Thunk then one can do something like this: ReadableAPI.getCategories().then((categories)=>{ console.log('after getCategories', categories) this.props.dispatch(addCategories(categories)) }) Isn't this more straightforward and achieves the same thing? This answer from Dan Abramov explains beautifully why you would want to use redux-thunk in your application. One more benefit of using redux-thunk in your application is that you keep your business logic separate from your view part (React in your case). We had a use case where our app was written in backbone and we wanted to re-write

How to listen for specific property changes in Redux store after an action is dispatched

痞子三分冷 提交于 2019-12-03 03:01:33
问题 I am currently trying to conceptualize how to handle dispatching an action in a component based on a data change after a dispatch in another component. Take this scenario: dispatch(someAjax) -> property in state updates. After this, I need another component dependent on this same property to know that is has updated and dispatch an action based on the new value. Rather than using some type of value.on(change... solution, what is the preferred way to handle this type of action 'cascading'? 回答1

Perform Ajax Fetch in a Redux Reducer?

社会主义新天地 提交于 2019-12-01 06:56:29
问题 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(

How to dispatch an Action or a ThunkAction (in TypeScript, with redux-thunk)?

有些话、适合烂在心里 提交于 2019-12-01 03:37:54
Say I have code like so: import { Action, Dispatch } from 'redux'; import { ThunkAction } from 'redux-thunk'; interface StateTree { field: string; } function myFunc(action: Action | ThunkAction<void, StateTree, void>, dispatch: Dispatch<StateTree>) { dispatch(action); // <-- This is where the error comes from } ...I get this error from the TypeScript compiler: ERROR in myFile.ts:x:y TS2345: Argument of type 'Action | ThunkAction<void, StateTree, void>' is not assignable to parameter of type 'Action'. Type 'ThunkAction<void, StateTree, void>' is not assignable to type 'Action'. Property 'type'

How to dispatch an Action or a ThunkAction (in TypeScript, with redux-thunk)?

穿精又带淫゛_ 提交于 2019-11-30 23:23:44
问题 Say I have code like so: import { Action, Dispatch } from 'redux'; import { ThunkAction } from 'redux-thunk'; interface StateTree { field: string; } function myFunc(action: Action | ThunkAction<void, StateTree, void>, dispatch: Dispatch<StateTree>) { dispatch(action); // <-- This is where the error comes from } ...I get this error from the TypeScript compiler: ERROR in myFile.ts:x:y TS2345: Argument of type 'Action | ThunkAction<void, StateTree, void>' is not assignable to parameter of type

How do I test a Redux action creator that only dispatches other actions

大城市里の小女人 提交于 2019-11-30 22:21:06
I'm having trouble testing an action creator that just loops through the array passed to it and dispatches an action for each item in that array. It's simple enough I just can't seem to figure it out. Here's the action creator: export const fetchAllItems = (topicIds)=>{ return (dispatch)=>{ topicIds.forEach((topicId)=>{ dispatch(fetchItems(topicId)); }); }; }; And here's how I'm attempting to test it: describe('fetchAllItems', ()=>{ it('should dispatch fetchItems actions for each topic id passed to it', ()=>{ const store = mockStore({}); return store.dispatch(fetchAllItems(['1'])) .then(()=>{

Redux: Using async middlewares vs dispatching actions on success functions

眉间皱痕 提交于 2019-11-30 15:24:11
I am trying to integrate Redux into my React project. Currently I'm not using any Flux framework. My app gets some data from the API and displays it in a pretty way, like so: componentDidMount() { getData(); } getData() { const self = this; ajax({ url: apiUrl, }) .success(function(data) { self.setState({ data: data, }); }) .error(function() { throw new Error('Server response failed.'); }); } In reading about Redux, I've settled on two possible approaches that I could use for handling storing my success data in the store: Use async middlewares, or Dispatching action ADD_DATA from the success

What are the benefits of using thunk middleware in redux over using regular functions as async action creators? [closed]

泄露秘密 提交于 2019-11-30 07:30:23
I've been using redux for about two months now and have just recently started getting into exploring different ways of dealing with asynchronous behavior such as fetching data. It appears from the documentation and from discussions on GitHub that the standard way of doing this by using the thunk middleware which is a pretty simple concept however I'm not sure if I understand the benefit in handing the responsibility of executing async state machines to redux middleware when a simple independent function could have been used. Traditional Redux approach using thunk middleware Async Action

How to dispatch multiple actions in react-navigation?

感情迁移 提交于 2019-11-29 11:53:24
I want to perform two actions but it doesn't work. const backAction = NavigationActions.back({ key: null }) const dispatchLogoutAction = NavigationActions.reset({ index: 0, actions: [NavigationActions.navigate({routeName: "LoginView"})] }); nextProps.navigation.dispatch(backAction); nextProps.navigation.dispatch(dispatchLogoutAction); What other ways to dispatch both actions in react-navigation rather than listing dispatch statements parallelly? 来源: https://stackoverflow.com/questions/48050248/how-to-dispatch-multiple-actions-in-react-navigation