logo
down
shadow

Redux reducer gets string instead of object


Redux reducer gets string instead of object

By : Cake
Date : December 05 2020, 12:18 PM
should help you out I am trying to update my state using redux, but for some reason the reducer only gets a string instead of an object. , You are passing the string action.activeTab into Object.assign
code :
const state = {};
const action = { type: 'SWITCH_TAB', activeTab: 'lines' };
const newState = Object.assign({}, state, action.activeTab);
console.log(newState);
const state = {};
const action = { type: 'SWITCH_TAB', activeTab: 'lines' };
const newState = Object.assign({}, state, { activeTab: action.activeTab })
console.log(newState);


Share : facebook icon twitter icon
Redux reducer add new object to array

Redux reducer add new object to array


By : Digvijay Thakur
Date : March 29 2020, 07:55 AM
will be helpful for those in need I'm having a problem adding new object to array of objects through dispatching action after submit. The purpose of this is showing flash messages across site. I have two components that are responsible for showing messages, FlashMessagesList and FlashMessage. Also server respond with message object, that needs to bee added to messages array. The problem is when action is dispatched, I can see that it is dispatched in redux devtools, but state never changed no meter what i do, it remains empty array, and I'm quite stuck with this, so any advice will be welcome. Here is the relevant code: , There's a typo in your reducer. Instead of
code :
switch (action.types) {
switch (action.type) {
How to add an object to an existing object, something like doing push in an array, but in reducer for redux

How to add an object to an existing object, something like doing push in an array, but in reducer for redux


By : F. Delmonte
Date : March 29 2020, 07:55 AM
will be helpful for those in need Goals: Be able to add, replace, remove items from an object. , First of all, do not mutate state:
code :
const newState = {...state};
const { all } = newState;
all[data.id] = data;
return {...state, ...{ all }};
Redux Reducer is returning an [Object Object] , However i want string?

Redux Reducer is returning an [Object Object] , However i want string?


By : user1473313
Date : March 29 2020, 07:55 AM
help you fix your problem In handling your action, you are returning an object (check the curly braces):
code :
return {
  ...state,
  sidebarname: action.payload
};
return action.payload
let initialState = { sidebarmenu: "wrapper slide-menu" };
...
export default function(state=initialState,action){
  ...
}
Adding an Object to Redux Reducer

Adding an Object to Redux Reducer


By : Suupa-Pad
Date : March 29 2020, 07:55 AM
With these it helps You have to update it as array. Do like this. if action.payload is a single object.
code :
return {...state, scoreList: [...state.scoreList, action.payload]}
return {...state, scoreList: [...state.scoreList, ...action.payload]}
Update value of nested Redux reducer object

Update value of nested Redux reducer object


By : user2441306
Date : March 29 2020, 07:55 AM
Any of those help If your COLUMN_STATE_UPDATE action is updating only the columnState part (assuming type in your payload as the key):
code :
case COLUMN_STATE_UPDATE:
    const { type } = payload;
    return {
       ...state,                     // keep the other keys as they were
       [type]: {                     // only update the particular one
           loading: true 
       }
    }
}
case COLUMN_STATE_UPDATE:
    const { type } = payload;
    return {
       ...state,                     // keep the other keys of state as they were
       columnState: {
           ...state.columnState,     // keep the other keys of columnState as they were
           [type]: {                 // only update the particular one
               loading: true
           }
       }

    }
}
Related Posts Related Posts :
  • angular 6 Please add a @NgModule annotation
  • Trying to cast element ID to class selector in jQuery
  • Swipe JS - Display 3 Slides at a time
  • Jasmine test to call function when value is null
  • Keep chrome javascript running even if page reload
  • The event.target.value is not insert the userinput into a variable
  • Exporting HTML tables to Excel (.xls) in a separate sheet
  • Jquery tooltip on dialog close button
  • access variable inside anonymous function from outside
  • How come func is called from a function?
  • How to change add and remove active class in JavaScript
  • how to toggle a specific div in javascript
  • How to get all the values from multiple keys of an array of object?
  • jQuery bind() unbind() and on() and off()
  • regular expression to find DD Month YYYY from a string
  • How to upload files from web client (HTML/jQuery form) to your Dropbox folder
  • Backbone history and require.js issue
  • Confusion over Classical and Prototypal Inheritance Javascript
  • How to take screen shot of current webpage using Javascript/JQuery?
  • Store meridiem in a variable
  • class declared inside closure vs standard class without closure
  • javascript confirm box always return true
  • dynamically changing the size of font size based on text length using css and html
  • Node.js - Getting the host IP address while on Amazon EC2
  • Confusing CSS, can anyone explain please
  • How to install v8-profiler on Windows 8 (64 bit) using npm?
  • Resolve promise based on another promise
  • google maps adding overlay layer above UI and markers
  • Style specific letter?
  • RangeError: Maximum call stack size exceeded with array.slice
  • node rest client get with local variable
  • If condition not executes while mouse move fastly
  • Count the number of displayed elements in a HTML list
  • Locate JavaScript source code in Emacs
  • Clean, Modular Code vs MV* Frameworks
  • infinite scroll without loading image
  • Backbone: reverse collection order with comparator
  • What do printers ignore?
  • jQuery UI .tabs() Contentless tab?
  • Execute Javascript alert() after page (visually) loaded
  • JavaScript - duplicating array doesn't work
  • Excessive clickable area below image
  • JavaScript Regex: Replace |b| with <b>
  • Unexpected value change in 2D array in JavaScript
  • Function doesnt see parameter as a array of objects
  • jQuery fetch keypress event on chrome and IE
  • How to enable jquery validate localization?
  • Cassandra map collection returned by node.js Helenus looks odd
  • angular ng-repeat with multiple filter options
  • Selecting Children without ID or Class names
  • How to uncheck a group of checkboxes when another checkbox is checked
  • Is hiding content by Javascript or jQuery Worth trying
  • Load XUL resource using javascript
  • XML to HTML text area from server file system
  • set focus() on textbox on form onload
  • es lint '' is assigned a value but never used' eventhough i have used it
  • Can "name" attribute be used for custom VueJS components
  • Get innerHTML of content when it is clicked
  • HTTPS causes CSS animations to not load? Very confused
  • How to hide other div apart from touched div to the band
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org