redux

Redux-thunk: API response keeps pending

﹥>﹥吖頭↗ 提交于 2019-12-24 18:39:50
问题 I am trying to develop an application, that is showing photos from Unsplash given a keyword. I managed to fetch specific photos using unsplash.js. In my actions, I have several action creators: export const fetchPhotos = () => ({ type: FETCH_PHOTOS }); export const receivePhotos = term => { const unsplash = new Unsplash({ applicationId: "id", secret: "secret", callbackUrl: "callback" }); console.log(term); const response = unsplash.search .photos(term, 1, 20) .then(toJson) .then(json => json)

Switch store using condition in render using redux

。_饼干妹妹 提交于 2019-12-24 18:30:38
问题 My application has 2 side, first side is the client app, second side is admin dashboard app. To make it DRY I decided to pass the store in the provider base on user role, so that I don't have to have 2 set of router. class App extends Component { constructor(props) { super(props) this.role = getUserRole() //get role from localstorage } renderSwitchProvider = store => ( <Provider store={store}> <BrowserRouter> <div className="App"> <Switch> <Redirect exact from="/" to="/dashboard" /> <Auth

Should “next” always be invoked last in Redux middleware?

不打扰是莪最后的温柔 提交于 2019-12-24 17:53:17
问题 tl;dr: Within a Redux middleware function, is it okay to dispatch a new action after calling next to finish updating the store? I'm building a HackerNews reader using Flutter and built-flutter-redux, based off of Brian Egan's TodoMVC example. It uses HN's Firebase-backed API to pull data: https://github.com/HackerNews/API My actions look like this right now: ActionDispatcher<Null> fetchHackerNewsTopStories; ActionDispatcher<List<int>> fetchHackerNewsTopStoriesSuccess; ActionDispatcher<Null>

Count items based on condition

徘徊边缘 提交于 2019-12-24 17:10:32
问题 The initial state of the store is: let initialState = { items: [], itemsCount: 0, completedCount: 0 }; When I dispatch an action with the type ADD_ITEM the new item is added to the items array and itemsCount is incremented (Although I'm not sure if I'm doing it correctly) case "ADD_ITEM": { return { ...state, items: [ ...state.items, { title: action.name, dateCreated: action.date, id: action.id, isChecked: false } ], itemsCount: state.items.length + 1 }; } and for TOGGLE_ITEM case "TOGGLE

Redux/React - Search field is not updating the redux state instantly

牧云@^-^@ 提交于 2019-12-24 15:03:22
问题 I am new to redux world and I am trying to make newspaper app. I am currently working on the search functionality where the user can search for specific newspaper title. The problem is that when I first types eg 'a' the state is ''. And when I type more eg 'b' the state shows that the term is 'a' when it should be 'ab'. I am using redux chrome tools to check this global state. My Actioncreator is really simple (only returns the term passed to it): export function search(term) { return{ type

How to get normal json object from Promise Object in react-redux [duplicate]

人盡茶涼 提交于 2019-12-24 14:27:02
问题 This question already has answers here : Handling async request with React, Redux and Axios? (4 answers) Closed last year . How to get normal JSON object from Promise Object in react-redux? My action.js contains: export function allEmp() { let url = "employees?access_token="; let result = ApiCall.getApiCall(url) .then(function (response) { return response; }) .catch(function (error) { return error; }); console.log("result",result); return { type: "ALL_EMP", payload: new Promise((resolve,

higher order function render twice causing child component to be triggered

北城余情 提交于 2019-12-24 14:09:48
问题 I have a protected route, implemented using higher order component, but in my App.js which is the child component, trigger its componentDidMount method, I wonder why is it so.. Route.js ... <BrowserRouter> <Switch> <Route exact path='/app' component={CheckPermission(App)} /> <Route exact path='/app/login' component={Login} /> </Switch> </BrowserRouter> ... Auth.js export default function CheckPermission(EnhancedComponent) { class Auth extends Component { static contextTypes = { router:

React/Redux—Individual state for each Instance of a Component

老子叫甜甜 提交于 2019-12-24 12:29:41
问题 If have a list of users and each Entry has a button »EDIT«. If the user clicks on it the following happens: request the server for the form Add the component <UserEditForm /> to the entry, what expands the entry This works fine except one thing: If one clicks further buttons each Instance of the form receives the data of the last user form requested. That is because I have only only one userform property in the state. So to solve this I want to exchange userform to userforms which should

Handling loading state of multiple async calls in an action/reducer based application

蓝咒 提交于 2019-12-24 12:16:58
问题 I don´t think this issue is bound to a specific framework or library, but applies to all store based application following the action - reducer pattern. For clarity, I am using Angular and @ngrx. In the application I am working on we need to track the loading state of individual resources. The way we handle other async requests is by this, hopefully familiar, pattern: Actions GET_RESOURCE GET_RESOURCE_SUCCESS GET_RESOURCE_FAILURE Reducer switch(action.type) case GET_RESOURCE: return { ..

How to update states of multiple reducers with a single action in ngrx store?

泄露秘密 提交于 2019-12-24 11:57:17
问题 I have multiple reducers in my application which are combined in app.reducers.ts. When my action happens state of one reducer should be update with single value from current state of the other reducer(so unplanned delivery will become scheduled) and then remove that value from state of second reducer. Here is how I can delete it, but before doing this I need to update other state. case UNPLANNED_ACTIONS.REMOVE_UNPLANNED_DELIVERY: return Object.assign({}, state, { deliveries: state.deliveries