redux

React ref returns a 'Connect' object instead of DOM

元气小坏坏 提交于 2019-12-12 07:15:36
问题 I'm trying to create dynamics refs for custom components created through the map function. class PostsList extends Component { constructor(props) { super(props); } componentDidUpdate = () => { console.log(this.refs); } render() { let posts = this.props.posts || []; return ( <div ref="test"> {posts.map((post) => { return <Post post={post} key={post.id} ref={post.id}></Post> })} </div> ); } } export default PostsList the console.log returns the correct DOM node for refs.test but for the ones in

React Native Redux createStore error:undefined is not an object(evaluating 'action.type')

梦想与她 提交于 2019-12-12 05:38:10
问题 I'm use Redux with ReactNative,I'd like to create a store with reducer And,I got error below, point to line 'switch (action.type)' in function switchToTab() in reducer.js undefined is not an object(evaluating 'action.type') Here is my actions.js export const SWITCH_TAB = 'switchTab' export function switchTab(index) { return { type: SWITCH_TAB, index: index } } Here is my reducer.js import { SWITCH_TAB } from './actions.js' export function switchToTab(state = {}, action) { switch (action.type)

Redux for maintaing data with React Stack Navigation stackwise

那年仲夏 提交于 2019-12-12 05:30:06
问题 I have a screen A , which contains navigable components. One of these components navigates to screen A itself but with different data passed from the triggered component. I am using Redux , and React-navigation. Please help me to know how can I store data of screen according to React Stack Navigation Stage. Stack 4 --> Product Screen[id=103] Stack 3 --> Product Screen[id=102] Stack 2 --> Product Screen[id=101](suppose it contains related products which navigates to Product Screen itself with

Moving handler functions outside of react component

旧时模样 提交于 2019-12-12 05:27:46
问题 I created a reusable date picker component that I want to use throughout my React app. The issue that I'm running into is that the handler functions that get called during user interactions are identical in every React component where I use my date picker. This means I need to move them to an external file. The question is once I move thess functions to an external file which is NOT a React component, how will I access the store and dispatch function? Did some research and came across the

Redux and ALL the application state

你说的曾经没有我的故事 提交于 2019-12-12 05:27:05
问题 in the Redux documentation is written: In Redux, all the application state is stored as a single object. And that starts my problem. I'm writing an application that will manage few entities with many data in a SPA (React + Redux) and something is concerning me in to using Redux and get some kind of lag because the quantity of data that I'll need to manage. I don't believe that transferring all the application state over Redux would be nice, because in some way, it may consume a lot of memory,

Populate value in input field directly from redux store

你离开我真会死。 提交于 2019-12-12 05:24:51
问题 Can I set my input fields value to redux store value? Or may I need to copy the props to my local state for this? <input placeholder={props.placeholder} value={props.value} /> props.value is coming from react-redux's Connect. But I can't change the value of input, I think this is because props is read only 回答1: You can set value that way, it's correct. To change such input value you have to add onChange event handler that will dispatch an action updating corresponding value in Redux store

How to pass a redux store into dynamically rendered redux-form component?

为君一笑 提交于 2019-12-12 04:57:38
问题 I have a React Redux application, which is using redux-form. Form is render dynamically by event. While it render, I'am getting an error Uncaught Error: Could not find "store" in either the context or props of "Connect(Form(FormCreate))" To fix error, I explicitly pass a store into Form component, as bellow render(<FormCreate store={store}/>, document.getElementById('form')) But store also needed by redux-form custom render fiedls. For example <Field store={store} component={renderField} type

Redux - Removing object from array nested in another array

萝らか妹 提交于 2019-12-12 04:54:20
问题 My Redux state stores a comments object which stores an array of comments. Each comment object has a replies array in it. I am passing both the parent comment ID and the reply ID to my reducer with the intention to remove the reply from the replies array. A simplified version of my top-level comments object looks like this: { "count": 4, "data": [ { id: 123, text: 'This is a comment', replies: [ { id: 479, text: 'This is a reply', }, { id: 293, text: 'This is another reply', }, ], }, { id:

Is it ok to create generic redux update action

↘锁芯ラ 提交于 2019-12-12 04:45:07
问题 Which approach is better and why? There could be more fields than just title and priority. Having separate action for all changes: const todoReducer = (state, action) { switch (action.type) { case 'CHANGE_TITLE' { return { ...state, title: action.title } } case 'CHANGE_PRIORITY' { return {...state, priority: action.priority} } } } Having one generic update function: const todoReducer = (state, action) { switch (action.type) { case 'UPDATE_PROPERTY' { return { ...state, [action.prop]: action

updating object within redux state array not re-rendering react component [duplicate]

对着背影说爱祢 提交于 2019-12-12 04:43:20
问题 This question already has an answer here : My Redux state has changed, why doesn't React trigger a re-render? (1 answer) Closed 2 years ago . I am trying to update a single chef within the chefs array in my redux state. An example of the array is as follows: [ { _id: 1, name: 'first chef' }, { _id: 2, name: 'second chef' }, { _id: 2, name: 'third chef' } ] I make a call to the API which then returns me the updated chef object. I basically find the related chef object in my current state,