Componentwillreceiveprops require no native response and reduction

Why my component WillReceiveProps does not work on my response, I use reactive navigation and reduction. I launch the gearbox entry button using immutable. in the store is already updated, but componentWillReceiveProps does not work, just go only to the WillUpdate and DidUpdate component

import React, { Component } from 'react'

class Main extends Component{
  constructor(props){
    super(props)
    this.state = {
     active : '',
     username: '',
     password: ''
  }
}

componentWillReceiveProps(newProps) {
 console.log(newProps.load(), 'Component WILL RECIEVE PROPS!')
}

componentWillUpdate(nextProps, nextState) {
 console.log(nextProps, nextState, 'Component WILL UPDATE!');
}

componentDidUpdate(prevProps, prevState) {
 console.log(prevProps,'Component DID UPDATE!')
}

handleButtonAction(actions){
 let user = this.state.username
 let pass = this.state.password
 if(actions === 'login'){
   this.props.login(user, pass)
 }
}

render(){
  const {navigation} = this.props;
return(
          <Button block onPress={()=>this.handleButtonAction('login')} style=
   {{marginLeft: 10, marginRight: 10}}>
            <Text>Login</Text>
          </Button>
   )}

const mapStateToProps = state =>({
  token: state.token
})

const mapDispatchToProps = dispatch => ({
 login: (user, pass)=> dispatch({type:"LOGIN", payload:'testing'}),
})

export default connect(mapStateToProps, mapDispatchToProps)(Main)

In Reducer, I already use immutable, but why with this update I still get Props on a component that is not called

const listProduct = (oldstate, value)=>{
 console.log(oldstate);
 let newState = {...oldstate, data: value.data.data}
 console.log(newState);
 return newState
}

const login = (oldstate, value)=>{
 let newState = {...oldstate, token: value}
 return newState
}

const initialState = {}

const product = (state=initialState, actions)=>{
 switch (actions.type) {
 case "GET_PRODUCK": return listProduct(state, actions.payload);
 case "LOGIN": return login(state, actions.payload);
 default: return state
}}

export default product
+4
source share
1 answer

componentWillReceiveProps will be called only when the props change and when this is not the initial rendering.

componentWillReceiveProps , , .

.

, login

this.props.login(user, pass)

this.props.dispatch(xyz.login(user, pass)},

0

Source: https://habr.com/ru/post/1684783/


All Articles