redux

Redux - where to prepare data

本小妞迷上赌 提交于 2019-12-24 02:45:23
问题 I am new in Redux and I have a problem. I have array of objects in state, after adding a new object in that array I want to change all other objects. For example, something like this: [{id : 0, visible: false}, {id : 1, visible: true}] - old array [{id : 0, visible: false}, {id : 1, visible : false}, {id : 2, visible : true}] - that I want Where I should prepare old state? As redux documentaion said, in reducers I shouldn't make anything with state, I just need to return new state. Can I

debugged the code I think it will be this function onSelect

人走茶凉 提交于 2019-12-24 02:27:08
问题 I had working code in react class but when I changed to React.Component the whole UI is breaking. debugged the code I think problem will be this function onSelect . since if I give console statements its not printing anything. can you tell me how to fix it. i even checked the css it is same. providing code below class Accordion extends React.Component { constructor(props) { super(props); 回答1: I've created a working solution here: JSFiddle It seems that React.cloneElement prepends a modifier

Can´t access props after using CombineReducer

十年热恋 提交于 2019-12-24 02:14:14
问题 My previous React-Redux implementation was working, but after I tried to implement the combineReducer function with seperated files, an error is thrown that I don´t really understand. Hope some of you can help me! ERROR: Uncaught TypeError: this.props.todos.map is not a function My Reference for that Code was the Async Example of the Redux-Doc´s. But I stated with another example and the change from each examples are not documented in the doc´s. The first code I will show, is that I had

Changing a child components state changes the parent components props

拥有回忆 提交于 2019-12-24 02:13:11
问题 Parent component is a header Child component is a form which is used to change values appearing in the header after a save which fires a redux action. I set the child state with constructor(props) { super(props); this.state = { object: { ...props.object }, hidden: props.hidden, }; } The form is used to render the state.object and modify the state.object. When I modify state.object, the props from the parent component change as well. handleObjectChange = (event, key, subkey) => { console.log(

React-router-redux takes two clicks on a Link to update location state

旧城冷巷雨未停 提交于 2019-12-24 01:57:10
问题 I have an issue with my app that I cannot find solution for anywhere. I use react-router-redux and syncHistoryWithStore . When I click on my navigation to change a route using Link the new route loads, URL in the browser updates, however the location state doesn't update unless I click the Link two times. UPDATE: I've noticed it might have something to do with Chrome React DevTools. If I open the React Devtools and select provider then unwrap the components tree one at a time, the location

Reducer behavior

拜拜、爱过 提交于 2019-12-24 01:51:47
问题 As I understand it, when an action is called, all reducers respond. If action exists in the switch case statement of the reducer, it executes. If it doesn't, then the case: default executes which preserves the existing state. When the action exists in the reducer but the particular property it's trying to update does not exist, it seems to behave OK as there's nothing to update. For example, I have an action creator that is used to set the visible property of my modals. Each modal has its own

Implementing history-api-fallback for Webpack Production environment

淺唱寂寞╮ 提交于 2019-12-24 01:43:09
问题 My stack is React/Redux as frontend together with React Router v4 and Firebase Hosting as backend. Like many others, I also faced the issue of meeting the 404 page not found when users refreshed at a page other than the root URL like https://example.com/about or manually key in the URL https://example.com/about. I researched many websites and HashBrowser seem to be a workaround for this problem but it is not a complete solution. It does not bring the user to the correct page but instead

react-redux: when mapDispatchToProps is object, how dispatch action works?

北战南征 提交于 2019-12-24 01:22:12
问题 During the usage of react-redux , I came across a confusing point about the mapDispatchToProps , when it is an object instead of function. For example, in my project, I have the following action creaters: export const incrementBy2 = () => ({ type: INCREMENT_REQUESTED_2, }) And in my component I import the action creator and set it up for mapDispatchToProps: import { incrementBy2 } from '../actions' import { connect } from 'react-redux' // define the Home component, omit the details const Home

Using react's context to allow rendering of a child component into a parent/grandparent/great-grandparent… Anti-pattern?

喜夏-厌秋 提交于 2019-12-24 01:18:23
问题 I have a proof of concept for this, which seems to work, but a part of me is wondering if this is really a good idea and if there is perhaps a better solution out there using something like Redux or an alternative strategy. The Problem Basically, I have a base React component for my entire application which has a bunch of typical components that you might expect, header, menu, footer etc etc. Further down my tree (much further) I have a component for which it would be awesome if I could mount

Best place to apply API response transformation [closed]

空扰寡人 提交于 2019-12-24 01:01:42
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . In an async action creator, I fetch data from the server. The data is not very well formatted for my use case and I need to transform it to use it in the UI. Question : should I Transform data just after it arrives before dispatching a success action with the transformed data