-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Description
Do you want to request a feature or report a bug?
I am retrieving data from Salesforce using JS remote Actions and populating data in React JS.
The structure of my application:
My component1.js:
import React from 'react';
const component1 = React.createClass({
getInitialState() {
return {
basicData : {},
interestData : {},
accountingData : {},
isLoading : true
}
},
componentWillMount() {
console.log('componentWillMount');
},
componentDidMount() {
console.log('componentDidMount');
this.props.action1();
},
componentWillReceiveProps(NextProps) {
console.log('componentWillReceiveProps', NextProps);
},
componentWillUnmount() {
console.log('componentWillUnmount');
},
render() {
console.log('RENDERING');
return (
<div>
<p> Loading! </p>
</div>
)
}
});
export default component1;
This is my container.js
import React, { Component } from 'react';
import { connect } from 'react-redux';
import RootComponent from '../components/component1.js';
import { action1 } from '../actions/actionCreators';
function mapStateToProps(globalState) {
return {
value1: globalState.value1,
value2: globalState.value2
};
}
const mapDispatchToProps = (dispatch) => {
return {
getData: () => {
dispatch(getData())
}
}
}
export default connect(mapStateToProps, mapDispatchToProps)(component1);
Action creator:
export function action1() {
return {
type: 'RETRIEVE_REQUESTED_DATA',
value1: getRecords()
};
}
Reducer:
case "RETRIEVE_REQUESTED_DATA":
action.value1.then(function(data) {
return testVar = { ...state, basicData: state.basicData, interestData: data, accountingData: state.basicData, isLoading: false};
});
Though, I am returning altered state from my reducer, MapStateToProps in my container is not being invoked.
The server call returns a promise and that promise is handled in reducer here, once the data is retrieved then I am populating the data to my state.
My view to the issue,
Once data is retrieved from DB (Salesforce), state is altered thus, MapStateToProps should be invoked because it is connected to the Component with Connect.
Please shed some light.
I am very new to Redux and React not sure whether this is a issue or a usage question, pls excuse my ignorance.