redux

useEffect in React not update component after update store

China☆狼群 提交于 2021-01-28 09:05:51
问题 I don't understand why React not update my object. In another component through the dispatch I update the state. In this (in code below) code in mapStateToProps categories are changing (console log show one more category). But component not rerender, although in component in useEffect I use props.categories. Event console.log in element does not run const LeftSidebar = (props: any) => { console.log('not render after props.categories changed') useEffect(() => { props.dispatch(getCategories())

React Redux sync action returns some Proxy object instead of string

一笑奈何 提交于 2021-01-28 09:01:57
问题 I have an input with currentAnswer : <input value={props.currentAnswer} onChange={(text) => dispatch(onChangeAnswer(text))} /> Which calls function onChangeAnswer : export function onChangeAnswer(text) { console.log(text); return { type: ON_CHANGE_ANSWER, data: text }; } Reducer: export default function reduce(state = initialState, action) { switch (action.type) { case ON_CHANGE_ANSWER: return assign({}, state, { currentAnswer: action.data }); Async actions works good, but when I change text

State not mapped to props react-redux

核能气质少年 提交于 2021-01-28 08:03:02
问题 I have a simple LoginForm and I try to map the states from redux to react. Here is my code from LoginForm.js: export class LoginForm extends React.Component { render() { console.log("**** FORM print store"); console.log(store.getState()); console.log("**** FORM print props"); console.log(this.props); if(this.props.loginObj.loginState=='true') { // error here console.log('yes'); } return ( <div><div/>); ); } } const mapStateToProps = (state) => ({ loginObj : state.loginObj }); const

Updating Functional Component Local State Using Data From Redux State

强颜欢笑 提交于 2021-01-28 08:01:29
问题 I'm building contact manager. When the user clicks the update button for a specific contact an action is dispatched and the "hotContact" property in the reducer's state is populated with an object. What I want is the fields of the ContactForm to be populated with the name and number of the "hotContact". However, despite the hotContact being loaded into the redux state my ContactForm component won't display the name and number of the hotContact. How can I proceed? This is what I have so far. I

React redux and React router,link change does not re render view [duplicate]

十年热恋 提交于 2021-01-28 07:29:38
问题 This question already has answers here : React router changes url but not view (22 answers) Closed 2 years ago . I a few <Link/> elements and a few corresponding components that are rendered via the <Route/> The components that are being rendered by <Route/> are redux connect -ed. On clicking the links,the url in the address bar changes but not the rendered component view. However,the proper view is rendered on refreshing. Code for the container component(the one with the Routers and Links)

Get wrapped component class from connected HOC in react-redux

懵懂的女人 提交于 2021-01-28 06:58:06
问题 When using the connect function in react-redux , a Higher Order Component is created. From an instance of that HOC, one can access the wrapped instance of the extended component. Is it possible, however, to retrieve the wrapped class from the HOC class? E.g.: class A extends React.Component {} ConnectedA = connect(mapStateToProps, mapDispatch)(A); ConnectedA.some_static_method_to_get_the_wrapped_class(); // === A EDIT: For the sake of clarity, I do not have an instance of ConnectedA available

Redux normalizr - how can i merge all normalized object together

ぃ、小莉子 提交于 2021-01-28 06:00:12
问题 I am using redux with normlizr after normalizing the object I got the following store structure: { posts: { byId : { "123":{..obj}, "124":{..obj} } }, comments: { byId : { "123":{..obj}, "124":{..obj} } }, users:{ byId : { "123":{..obj}, "124":{..obj} } } } the ids are the same as the posts (post is the parent lets say) so when I select all posts I got smth like : { posts : [ { "id" : "123", ...data "comment":"123", "user": "123" } ] } but I would like the data of comment and user also inside

Mongoose model not persisting object

一曲冷凌霜 提交于 2021-01-28 05:13:44
问题 In a nutshell, I'm working on a math assessment app that takes your answers and stores them in a database and I'm having trouble adding more than one object to the backend. The Mongoose model is as such: const mongoose = require('mongoose'); const Algebra1Schema = new mongoose.Schema({ user: { type: mongoose.Schema.Types.ObjectId, ref: 'user' }, answers: { type: Object }, date: { type: Date, default: Date.now } }) module.exports = algebra1 = mongoose.model('algebra1', Algebra1Schema) Here is

Why can't I use nested yield in for..in loop in Redux-Saga

♀尐吖头ヾ 提交于 2021-01-28 05:13:28
问题 So I have tasks object with ids and values. With for in loop I want to read 'members' property. If it exist, and first element of array !=='all' I want to make request to firebase for read document by given id. But I cant use yield , there is error: Failed to compile. ./src/containers/modules/Tasks/store/sagas/tasksSagas.js Line 27: Parsing error: Unexpected reserved word 'yield' Why am I getting it? I can't use nested yields? //Fetching users for tasks for (const task in tasks) { if (tasks

REACT REDUX: Update value in deep nested object

不问归期 提交于 2021-01-28 04:21:55
问题 I am trying to update a value stored in a deep nested object. It contains many pieces of information and the schema is fixed. I am trying to copy the object then return the object with update value onChange from an input. However I am unable to successfully correctly copy the full tree and return the updated content. DEMO : https://codesandbox.io/s/4j7x8jlk9w the object looks like: content: { label: "Label", templates: [ { name: "example", type: "the type", items: [ { key: "key1", properties: