Questions tagged [mapstatetoprops]

58 questions
49
votes
3 answers

mapStateToProps vs mapDispatchToProps

What's the difference between mapStateToProps and mapDispatchToProps arguments to the connect function in react-redux?
Lex V
  • 1,414
  • 4
  • 17
  • 35
3
votes
2 answers

How to retrieve data from Redux store using functional components and avoiding useSelector & useDispatch

I'm doing an attemp of Todo App in React- Redux; got store, actions, reducer & Addodo component running; but got stucked at showing todos: if my initialState=[] how can i retrieve data from store? Store: import { createStore } from 'redux'; import…
Martin Gonzalez
  • 77
  • 1
  • 1
  • 12
3
votes
1 answer

How to get entities as an array in a class component when using createEntityAdapter from Redux toolkit?

I have a slice in my store I created with createEntityAdapter from Redux Toolkit. In Function components you can use useSelector with the selectors returned from adapter.getSelectors(). But how can I get all entities as an array (like with the…
2
votes
2 answers

How do I pass a URL Param to a selector

I recive a url param from useParams. I want to pass it to a selector using mapStateToProps. collection.component.jsx import { useParams } from "react-router-dom"; import { connect } from "react-redux"; import { selectShopCollection } from…
2
votes
2 answers

I'm confused about the arguments that i passe to a selector function that uses reselect inside containers

I'm learning the usage of reselect, but i'm confused about the way i make use of the memoized selector in inside my container. I've got a component called Summary that received 3 props thats are subtotal, tipAmount , total . It looks like this…
Christian LSANGOLA
  • 2,947
  • 4
  • 22
  • 36
2
votes
1 answer

How does this arrow function work in my special case passing it through Redux

I learn JavaScript and React Redux and have this question:. Let's say I have this Redux dispatch: dispatch(setLogMessage( () =>{"Connecting to env1", 12340, "connecting"})); and the reducer is here for the above setLogMessage is this: const…
Kid
  • 1,869
  • 3
  • 19
  • 48
2
votes
1 answer

How do I properly map an array in which it's coming from one of my properties defined in mapStateToProps for a select drop down in my form?

The below code is from my NewFighterForm.js file within my app's component folder: import React from 'react'; import { updateNewFighterForm } from '../actions/newFighterForm.js'; import { connect } from 'react-redux'; import Button from…
1
vote
2 answers

React: Is it better to pass something as a prop to a child component, or have that child component get it from Redux?

I have components and , and accesses a Redux state prop called prop1 using mapStateToProps(). needs to access prop1 as well. What's the difference between passing it to as a prop like
gkeenley
  • 6,088
  • 8
  • 54
  • 129
1
vote
1 answer

TypeError: Cannot read property 'selectedTab' of undefined

I was working with React Native and all seem smooth. But suddenly this error occur. I don't know why. Before this, this error not happened. Please help me... The error is: TypeError: Cannot read property 'selectedTab' of undefined The code is…
1
vote
0 answers

Difference in the value received in this.props when using mapStateToProps (react-redux) vs store.getState()

I am facing an issue in my code base so I have made a sample code to demonstrate the issue. link for the codesandbox code App.js import React, { Component } from 'react'; import './App.css'; import { connect } from 'react-redux'; import {…
ash1102
  • 409
  • 4
  • 20
1
vote
1 answer

TypeError: ownProps.match is Undefined

Unable to find a solution to the error TypeError: ownProps.match is undefined. I am following a tutorial on react-redux and firebase to build a to-do app. The below code gives the component where I am redirected to when I click my Task/project on…
nikkbh
  • 77
  • 5
1
vote
1 answer

React Native Redux - Why can't I access data in my redux store and display it?

I completed the React Native course on Coursera and have a working app using redux and json-server to show data. I am now making my own app and I'm having a lot of trouble with redux not showing my data when I try to access it. After trying to…
1
vote
1 answer

React Redux accessing dynamically filtered state in mapStateToProps - rerendering woes

I have a functional component, that is passed instructions on what to pull from the redux store. Using mapStateToProps=(state, ownProps), I can happily pull the required items from state (store) - but, at a cost of any changes in the entire state…
skavan
  • 417
  • 1
  • 9
  • 17
1
vote
1 answer

How to call a mapStateToProps path with numerous dynamic variables (React-Redux)

Not sure exactly what the correct syntax for this is, but I am trying to get the value (string) of the courseTitle variable found in state as the following path (when typing console.log(state): state |_____ firestore |______________…
Andrew B.
  • 245
  • 3
  • 12
1
vote
0 answers

React + Redux binding child component methods to parent or keep them on their own

We have an react redux appl. We have a parent class bound to redux It is our parent class: render() { return (
.. const mapStateToProps = (state, ownProps) => ({ parentRelatedFooVar: state.parentRelatedFooVar }) const…
benchpresser
  • 2,171
  • 2
  • 23
  • 41
1
2 3 4