redux

Redux store does not have a valid reducer

不问归期 提交于 2019-12-18 12:13:21
问题 Haven't been able to find anything around here regarding this error: "Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers." My reducer export default function FriendListReducer(state = {friends : []}, action) { switch (action.type) { case 'ADD_FRIEND': return [ { friends : action.payload.friend }, ...state.friends ] default: return state; } return state; } Combiner import { combineReducers } from 'redux'; import {

Using redux-form I'm losing focus after typing the first character

早过忘川 提交于 2019-12-18 11:52:17
问题 I'm using redux-form and on blur validation. After I type the first character into an input element, it loses focus and I have to click in it again to continue typing. It only does this with the first character. Subsequent characters types remains focuses. Here's my basic sign in form example: import React, { Component } from 'react'; import { connect } from 'react-redux'; import { Field, reduxForm } from 'redux-form'; import * as actions from '../actions/authActions'; require('../../styles

Right way to update state in redux reducers

爱⌒轻易说出口 提交于 2019-12-18 11:51:20
问题 I'm a newbie in redux and es6 syntax. I make my app with official redux tutorial, and with this example. There is JS snippet below. My point - to define REQUEST_POST_BODY and RECEIVE_POST_BODY cases in posts reducer. Main difficult - to find and update right object in store. I try to use code from example: return Object.assign({}, state, { [action.subreddit]: posts(state[action.subreddit], action) }) But it used simple array of posts. It's not needed to find right post by id. Here my code:

Pass state to recursively nested component in React/Redux

亡梦爱人 提交于 2019-12-18 11:47:20
问题 I have a component that has children of the same type as the component itself. I can render the children as well but the children can't seem to access their slice of state. I'm using React with Redux export class Material extends React.Component { constructor(props) { super(props) this.renderChild = this.renderChild.bind(this) this.getNestedItems = this.getNestedItems.bind(this) } static propTypes = { parentId: PropTypes.number, id: PropTypes.number.isRequired, name: PropTypes.string

typescript + redux: exclude redux props in parent component

断了今生、忘了曾经 提交于 2019-12-18 11:39:50
问题 I am using redux and typescript for my current webapp. What is the best practice to define the props of a component which receives redux-actions via @connect , but also props from parent? Example: // mychild.tsx export namespace MyChildComponent { export interface IProps { propertyFromParent: string; propertyFromRedux: string; // !!!! -> This is the problem actionsPropertyFromRedux: typeof MyReduxActions; // !!!! -> And this } } @connect(mapStateToProps, mapDispatchToProps) export class

React router v4 not working with Redux

笑着哭i 提交于 2019-12-18 11:12:14
问题 Developing a React application using React router v4. All worked well until I introduced Redux in my app. Since then on click of links to change route the browser url changes but the component corresponding to the route is not getting loaded. It works well if I comment out Redux code. What could be causing this? Here is my code for routing: import React, { Component } from 'react'; import { Switch, Route, Link } from 'react-router-dom'; import LeftSubDefault from './../components/left-sub

When do I choose React state Vs Redux Store

谁都会走 提交于 2019-12-18 10:51:28
问题 I've been learning Redux and a part I'm unclear of is, how do I make a determination between using react state vs redux store and then dispatching actions. from my reading so far it looks like I could use React state in place of Redux store and still get things done. I understand the separation of concerns with using Redux store and just having 1 container component and the rest of it as stateless component but how do I make the determination of when to use React state Vs redux store is not

All reducers will be invoked when an action is dispatched?

走远了吗. 提交于 2019-12-18 10:39:50
问题 I am using combineReducers to combine all the reducers to create the store, does it mean that any action dispatched from any view will trigger all the reducers being invoked to check the action type?Is it kind of low efficiency? Or I don't fully understand the redux design principle? 回答1: Yes, that is correct. However one option you have to optimize this behaviour (suggested from the Redux docs) is to use 'reselect' https://github.com/rackt/reselect Reselect basically allows you to create

What's the Difference between mapstatetoprops and mapdispatchtoprops [duplicate]

假如想象 提交于 2019-12-18 10:28:22
问题 This question already has answers here : What is mapDispatchToProps? (6 answers) Closed last year . What's the difference between mapStateToProps and mapDispatchToProps arguments to the connect function in react redux ?? Can anyone give a suitable explanation with examples 回答1: mapStateToProps is a function that you would use to provide the store data to your component, whereas mapDispatchToProps is something that you will use to provide the action creators as props to your component.

How to properly make REST calls from ReactJS + Redux application?

女生的网名这么多〃 提交于 2019-12-18 10:27:36
问题 I'm using ReactJS + Redux, along with Express and Webpack. There is an API built, and I want to be able to make REST calls -- GET, POST, PUT, DELETE -- from the client-side. How and what is the properly way to go about doing so with the Redux architecture? Any good example of the flow, in terms of reducers, action creators, store, and react routes, would be extremely helpful. Thank you in advance! 回答1: The simpliest way, is to do it using redux-thunk package. This package is an redux