redux

Redux: Normalizing Global State

て烟熏妆下的殇ゞ 提交于 2020-01-05 05:37:07
问题 Assume the following situation: 1. Page has many posts 2. Post has many comments I have the following reducers: 1. PagesReducer 2. PostsReducer 3. PostReducer 4. CommentsReducer I have the following state right now: pagesByTitle: { dorrisPage: { isFetching: false, data: { _id: "..." title: "dorrisPage", }, posts: [ { isFetching: false, data: { _id: "..", body: ".." }, comments: [..] } ] } } The above structure looked okay initially, but I realized that I had to pass down the action for child

Explain Redux : mutation and asynchronicity

喜夏-厌秋 提交于 2020-01-05 04:29:09
问题 I could not understand what the below lines on first page of REDUX mean https://redux.js.org/introduction/motivation This complexity is difficult to handle as we're mixing two concepts that are very hard for the human mind to reason about: mutation and asynchronicity. I call them Mentos and Coke. Both can be great in separation, but together they create a mess. Libraries like React attempt to solve this problem in the view layer by removing both asynchrony and direct DOM manipulation .

conditional async actions in componentDidMount lifecycle method keeps going on a loop

谁都会走 提交于 2020-01-05 03:57:04
问题 I am working on a react app using redux and sagas connected to an API. There's a form component that has two dropdown fields: a Program and a Contact field. The way the form is designed to work is, when the user selects a program, the form uses the programId to fetch all the contacts that have registered for that program. These contacts are then populated as the options for the contact dropdown field. This works and I've implemented it using the componentWillReceiveProps, like this:-

Why does redux dispatch happen before hook values are updated?

*爱你&永不变心* 提交于 2020-01-05 03:49:04
问题 I have an interesting problem in my code and I am not sure why it happens. Hopefully someone can explain. Basically, I am using "setValues" for my hooks before I call the "dispatch"-method. However, it seems like dispatch is still triggered before the values in the hooks are updated. Even though to me it seems like it should be the other way around. Why does this happen? Here is some of the code: import React, { useState } from 'react'; import Grid from '@material-ui/core/Grid'; import

bindActionCreators and mapDispatchToProps - Do I need them?

本小妞迷上赌 提交于 2020-01-04 15:11:13
问题 I'm looking at a React-Redux app and try to understand how everything is working. Inside one of the components, I saw these lines of code: import { bindActionCreators } from "redux"; ... function mapDispatchToProps(dispatch) { return bindActionCreators({ fetchPhotos }, dispatch); } export default connect( null, mapDispatchToProps )(SearchBar); If I change the above code to the following, everything still works, without any errors: function mapStateToProps(photos) { return { photos }; } export

Redux Saga: How to wait for spawn and call to complete without blocking parent call

耗尽温柔 提交于 2020-01-04 14:17:37
问题 I'm trying to add a redux saga function but I can't get the chaining right const randomDelay = () => parseInt(Math.random() * 500) const a = function*() { yield spawn(b) yield call(c) } const b = function*() { yield delay(randomDelay()) } const c = function*() { yield delay(randomDelay()) } const d = function*() {} I want to call a which will spawn b and call c . When c is complete I want a to become unblocked and complete. When b and c both complete I want to call d From what I can tell

React server side rendering and lazy loading of webpack

旧街凉风 提交于 2020-01-04 09:17:55
问题 I am using server side rendering with lazy loading of Webpack 2.2.0 using import() method, and using babel-plugin-transform-ensure-ignore for server side only, everything runs without errors and perfectly working except one thing. when page is loaded I can see server side rendering, but when webpack calling my dynamic component, all page renders again, which is visible for users. I need to know how to handle such problems. I found it when saw that, my first line is <div data-reactroot="" data

Select box not changing after changing the value from redux-devtools

我们两清 提交于 2020-01-04 07:31:10
问题 locale is in my redux app state. Changing its value through react-devtools (revert option), changes paragraph inner value but not the select box value. If it renders again shouldn't it take the same value as inside the p tag? import React, {Component, PropTypes} from 'react' import {defineMessages, injectIntl, intlShape} from 'react-intl' const messages = defineMessages({ spanish: { id: 'languageSelector.spanish', description: 'Select language', defaultMessage: 'Spanish' }, english: { id:

Select box not changing after changing the value from redux-devtools

最后都变了- 提交于 2020-01-04 07:31:07
问题 locale is in my redux app state. Changing its value through react-devtools (revert option), changes paragraph inner value but not the select box value. If it renders again shouldn't it take the same value as inside the p tag? import React, {Component, PropTypes} from 'react' import {defineMessages, injectIntl, intlShape} from 'react-intl' const messages = defineMessages({ spanish: { id: 'languageSelector.spanish', description: 'Select language', defaultMessage: 'Spanish' }, english: { id:

Redux with React - right way to share the store with components

感情迁移 提交于 2020-01-04 06:08:45
问题 The store service from Redux is what ultimately utilized by various components in a React App. The methods (such as dispatch, getState and subscribe) exposed by it are used by all kinds components (like container or presentational). I think the approach to pass this store service around is an important design decision. I see two approaches and they are: 1) By passing the store as a prop to every component at all nested levels. This is not the recommended one. 2) Use a tool like react-redux,