Michael
Michael

Reputation: 621

react-native-router-flux: onLeft scene

I'm trying to add onLeft for a scene employeeEdit scene when returning from the scene should the user not wish to make changes to the current selected employee that they'll be able to return to the employee list and the fields will be emptied when going onto Add by using type: 'reset' as if were to save changes.

It seems that the onLeft is not working in this case here in that the function is not actually being executed.

<Router sceneStyle={{ paddingTop: 65 }}>
    <Scene key="auth">
        <Scene key="login" component={LoginForm} title="Please Login" initial />
    </Scene>

    <Scene key="main">
        <Scene 
            onRight={() => Actions.employeeCreate()}
            rightTitle="Add"
            key="employeeList" 
            component={EmployeeList} 
            title="Employees" 
            initial
        />
        <Scene
            key="employeeCreate" 
            component={EmployeeCreate} 
            title="Create Employee" 
        />
        <Scene
            onLeft={() => Actions.employeeList({ type: 'reset' })}
            key="employeeEdit" 
            component={EmployeeEdit} 
            title="Edit Employee" 
        />                
    </Scene>
</Router>

Upvotes: 0

Views: 644

Answers (1)

Michael
Michael

Reputation: 621

A longer approach.

Using componentWillUnmount, this is effective when leaving the component i.e. EmployeeEdit

componentWillUnmount () {
    this.props.employeeInitial();
}

and this can then call a prop of gigInitial; having an action which will return a dispatch say of type: 'EMPLOYEE_INITIAL'

export const employeeInitial = () => {
    return (dispatch) => {
        dispatch({ type: EMPLOYEE_INITIAL });
    };
};

which at the EmployeeFormReducer will then just return INITIAL_STATE

case EMPLOYEE_INITIAL:
    return INITIAL_STATE;

Upvotes: 1

Related Questions