const INITIAL_STATE = {
otherStates...,
phase: " "
};
const mapStateToProps = (state) => {
return {
phase: state.phase
}
}
const mapStateToProps = (state) => {
return {
phase: state.phase
}
}
const mapDispatchToProps = (dispatch) => {
return {
onStarting: () => {
dispatch({type: 'STARTING'})
}
}
}
const ConnRootContainer =
connect(mapStateToProps, mapDispatchToProps)
(RootContainer);
I've got a switch statement below and in one case I need to assign phase some text.
export default function (state = INITIAL_STATE, action) {
switch (action.type) {
case types.STARTING:
let phase = " "
if (state.stateOne < state.StateTwo) {
count = growth(state, 0)
phase = "START"
}
else if (CONDITION) {
phase = "PAUSE"
}
else {
phase = "STOP"
}
coordinates = generate(state.coordinates, variable);
return {
...state,
coordinates: coordinates,
phase: phase
}
case types.OTHER_TYPE:
OTHER CASE FILES
}
default:
return state
}
}
Phase name has to be used as a condition in another function of same file.
let generate = (data, otherData) => {
if({this.props.phase} === "START"){
for (let i = 1; i < otherData; i++) {
let newX = data[i - 1].x + FORMULA;
let newY = data[i - 1].y + FORMULA;
data.push({ x: newX, y: newY });
}
}
if({this.props.phase} === "STOP"){
while (data.length) {
data.splice(data.length - 1, 1);
}
}
return data;
}
The new error is: this is a reserved word as phase is not passed to the function. How can I improve my code and use state.phase in if statement for validation?