redux

Redux actions/reducers vs. directly setting state

戏子无情 提交于 2019-12-12 18:39:48
问题 I'm new to Redux. I'm having trouble understanding the value of actions and reducers vs. components directly modifying the store. In Redux, your React components don't change the store directly. Instead they dispatch an action -- sort of like publishing a message. Then a reducer handles the action -- sort of like a message subscriber -- and changes the state (more precisely, creates a new state) in response. I feel like the pub/sub-like interaction adds layers of indirection that make it

React textarea with value is readonly but need to be updated

时光毁灭记忆、已成空白 提交于 2019-12-12 18:35:10
问题 I have a textarea in my React app who is filled with a value. I want this textarea to be updated and the form submited to update the row in the database. <textarea id="description" className="materialize-textarea" length="120" value={description} disabled={isDisabled}></textarea> The description variable fill the textarea with the value from the database. The field is not disabled. I tried to attach an onChange event who dispatch an action (redux) to change the value of the textarea, but it

Redux updating nested data [Immutable Update Patterns]

亡梦爱人 提交于 2019-12-12 17:50:17
问题 Can anyone help with this update pattern. I am not using any libraries like immer. I have to update a nested object and the data looks like dis Sample data { isFetching: false data:{ nba : { stack :{ 1:[] } } } } My Reducer { ...state, isFetching: false, data: { ...state.data, [action.payload.team]: { ...state[action.payload.team], [action.payload.framework]: { ...state[action.payload.framework], [action.payload.build]: action.payload.resp } } } }; I am able to update until second level but

Javascript const coming up as undefined and not undefined in chrome dev console

假如想象 提交于 2019-12-12 17:45:41
问题 I have a const newProducts that is returning undefined and yet says it isn't undefined in the chrome dev console: It says it is defined in the yellow highlighted text in the console, and undefined when hovering over it. It shouldn't be undefined. I have stepped through the code and the returns inside the map are returning values. Why is this const coming up undefined and also not undefined ? searchResults.reducer.js // @flow import initialState from '../../config/config' import { FETCH

react-redux react-router store not available in props

痴心易碎 提交于 2019-12-12 17:14:08
问题 I just started to use redux on my react site. Pretty small. (and I'm following this tutorial https://medium.com/front-end-developers/handcrafting-an-isomorphic-redux-application-with-love-40ada4468af4#.mhkgga84t plugging in some codes to my react site just in case). But when I was in progress and trying to acceess this.props.store it's not available even when I have <Provider store={store}> in my app. Here's my client and app code (I can provide more I just don't know what else to add): //

Redux action creator syntax

老子叫甜甜 提交于 2019-12-12 17:06:49
问题 function addTodoWithDispatch(text) { const action = { type: ADD_TODO, text } dispatch(action) } http://redux.js.org/docs/basics/Actions.html#action-creators I saw the code above from redux documentation. What I don't understand is the text in the action . It doesn't look like a valid javascript object or array syntax. Is it an ES6 new syntax? Thanks. 回答1: It is just a new ES6 syntax, which simplifies creating properties on the literal syntax In short, if the name is the same as the property,

change value deep in redux state

旧街凉风 提交于 2019-12-12 17:01:55
问题 context I'm rendering a form with a dynamic set of text elements. I've normalised my state using normalizr principles so there is an array of elementIds and an object containing the element properties referenced by the elementIds (see initial state in code sample below). aim My aim is simply for the two rendered elements to be editable. I'm successfully dispatching an action CHANGE_ELEMENT_VALUE to my store using an onChange callback, and action.id (referencing the id of the changed element)

Actions must be plain objects while using Redux

不羁岁月 提交于 2019-12-12 15:42:29
问题 Im getting an error like Actions must be plain objects. Use custom middleware for async actions while using react redux. Im developing an application with a login functionality. Here is my code. component import React, { Component } from 'react'; import PropTypes from 'prop-types'; import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; import Paper from 'material-ui/Paper'; import TextField from 'material-ui/TextField'; import RaisedButton from 'material-ui

can't change nested object in a reducer even when not mutating the objects and arrays

早过忘川 提交于 2019-12-12 15:18:46
问题 I'm trying to update a state inside a reducer, i know i shouldn't mutate the object or nested objects so I'm using map for arrays or object spread for objects. but it seems i can't really change a value that is deeply nested. Beside the fact that i can't change the state, i really dislike how the code looks and especially the number of loops i need to do to just change one property. I feel like there is a better, readable and more performant way of doing this. this is the state: const items =

Component rendering too early

南楼画角 提交于 2019-12-12 15:16:34
问题 I am trying to create a PrivateRoute(HOC) to test if a user has been authenticated(check is 'auth' exist in redux store) before sending them to the actual route. The issue is the privateroute finishes before my auth shows up in redux store. The console.log runs twice, the first time, auth doesnt appear in the store, but it does the second time, but by that time, its already routed the user to the login screen.... How can I give enough time for the fetch to finish? I know how to do this