react-redux

react component - parent child interaction; component Lifecycle

我怕爱的太早我们不能终老 提交于 2020-01-15 09:24:09
问题 I am developing a simple browser app to get some specific data from the user. I have several components to simplify the proccess of collecting that data, but I am currently rethinking my way of rendering this component. Basically, i have my main component, which uses state to keep track of which component to render. I am doing this for almost all of my components. Also, i also have a function inside the parent component, that i pass to the child component via props, and that is used as a

React Redux store state change is not working

人走茶凉 提交于 2020-01-15 08:55:22
问题 The below super simple code is not working as expected. I am using react and injecting/providing props via redux store. what my understanding is store inject props in the React component. To make this component work why I need both line1 and line 2 ? import React from 'react'; import './sytles.css'; import { fetchUsers } from "./actions/userAction" import { connect } from "react-redux" @connect((store) => { return { signup: store.users, }; }) class Signup extends React.Component { handleClick

React/Redux dispatch not triggering reducer

岁酱吖の 提交于 2020-01-15 05:37:30
问题 Struggling to dispatch an action from my React component. This is my first Redux app. Everything seems to be working fine, but if it was I would not be posting this question. I am using Redux devTool to debug my app. If I use the dispatcher from the devTools my reducer is triggered with no problem. However I am unable to dispatch the same action from my React components. I added a breakpoint in my action to see if it was being triggered. I definately is and it is also returning a valid action

Promise not returning when using mapDispatchToProps

旧时模样 提交于 2020-01-15 02:29:21
问题 Recently I've transitioned from using one optimistic action to adding two more to detect success/failure server responses. With the optimistic approach I was able to just pass in my action the shorthand way and chain from the promise: class Post extends Component { onUpdateClick(props) { this.props.updatePost(this.props.params.id, props) .then(() => /* Action goes here */); } } ... export default connect(mapStateToProps, { updatePost })(Post); Now that I'm dispatching multiple actions and

React Hook “useSelector” is called in function

。_饼干妹妹 提交于 2020-01-14 17:20:23
问题 I cannot figure out what going on with "useSelector" I need little help, please. ERROR React Hook "useSelector" is called in function "render_user" which is neither a React function component or a custom React Hook function class Navigationbar extends Component { onLogoutClick = e => { e.preventDefault(); this.props.logoutUser(); //this.props. }; render() { const render_user = () => { const auth = useSelector(state => state.auth); Error Message is here //More Code Here ); }; } Navigationbar

React Hook “useSelector” is called in function

老子叫甜甜 提交于 2020-01-14 17:12:31
问题 I cannot figure out what going on with "useSelector" I need little help, please. ERROR React Hook "useSelector" is called in function "render_user" which is neither a React function component or a custom React Hook function class Navigationbar extends Component { onLogoutClick = e => { e.preventDefault(); this.props.logoutUser(); //this.props. }; render() { const render_user = () => { const auth = useSelector(state => state.auth); Error Message is here //More Code Here ); }; } Navigationbar

Is it OK for a reducer to listen to other actions?

折月煮酒 提交于 2020-01-14 13:28:08
问题 At the moment I'm creating actions and then a reducer to handle different parts of my app... the different domains. My app lists classes and pupils. Currently I have an action that the app has loaded so that I know when to remove the loading spinner, I have actions for classes and pupils. My problem is that I find I need to execute several actions in a row and am not sure if this is a valid way to use redux. Here is an example function that dispatches several actions after the data is loaded:

How to get Mern Stack to work on Heroku

喜夏-厌秋 提交于 2020-01-14 06:05:07
问题 I'm testing out the Mern Stack (Mongo Express React/Redux Node) and set it up with development with no issue. Now I'm trying to deploy to Heroku. I did a git push heroku master just like normal, but when I check out the website I see Heroku's Application Error. I added a MongoDB through Heroku, and changed my heroku config variables, so it uses that db (I think I did this correctly). So I check into logs: npm ERR! file sh npm ERR! code ELIFECYCLE npm ERR! errno ENOENT npm ERR! syscall spawn

Using redux with react hooks

ε祈祈猫儿з 提交于 2020-01-14 04:59:06
问题 I'm trying to figure out the best way to use redux with react hooks. I saw the following How to use React hooks + Redux However I'm not convinced this is the best way to go. Does anyone have any alternative ideas? I also saw the following and seems quite good. https://www.npmjs.com/package/redux-react-hook Thanks 回答1: The official react-redux package provide hooks since v7.1. Redux hooks can be used instead of the connect(mapStateToProps, mapDispatchToProps) function. useSelector() Extract

React Redux - changes aren't reflected in component

跟風遠走 提交于 2020-01-13 19:33:23
问题 I created a simple React component for generating menu, and I wanted to replace it's visibility toggling with Redux (instead of state). My component looks like this: class SiteMenu extends React.Component { constructor(props) { super(props); } toggle(force = false) { let active = !active; store.dispatch({ type: 'TOGGLE', active }); } render() { const wrapperClass = this.props.active ? `${this.props.className}__wrapper ${this.props.className}__wrapper--active` : `${this.props.className}_