I am using React Navigation for routing. When the user opens up a Stock Item to modify, I want to add a Save button that gets all modified variables from the redux state
and queries them to an API endpoint
Currently I have only been able to add the save button in a very static sense like so:
const Stack = createStackNavigator(
{
Home: {
screen: Tabs,
navigationOptions: {
header: null,
},
},
StockScreen: {
screen: StockScreen,
navigationOptions: {
headerRight: (
<Button
onPress={() => {
alert('This is a button!');
}}
title="Save"
color="#fff"
/>
),
},
},
},
{
}
);
And I have my tab navigator:
let StockTabs = createMaterialTopTabNavigator(
{
General: {
screen: GeneralStockTab,
},
Pricing:{
screen: PricingTab,
},
Stock:{
screen: StockTab
},
Other:{
screen: OtherTab,
},
},
{
}
);
Now this tabbed nav is connected to redux like so:
const mapStateToProps = state => ({
item: state.stockItem.item,
itemLoading: state.stockItem.loading,
itemError: state.stockItem.error,
});
const mapDispatchToProps = (dispatch) => {
return ({
fetchStockItem: bindActionCreators(fetchStockItem, dispatch)
})
}
const mergeProps = (state, dispatch, ownProps) => {
return ({
...ownProps,
screenProps: {
...ownProps.screenProps,
...state,
...dispatch,
}
})
}
export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(StockTabs);
I want to be able to have a dynamic boolean to allow the save button to be pressed or not, depending on if values are modified, and when save is pressed I want to run a redux function to update the state
and query api.