reactjs - Calling (helper) function in redux -


i'm using react-native-router-flux react-redux , think should ask question here, correct me if i'm wrong.

i have activitymodal container call show whenever there api call or similar thing want show modal. i'm calling this:

actions.refresh({key: 'activitymodal', visible: true}); show , actions.refresh({key: 'activitymodal', visible: false}); hide.

this works i'd rather make more elegant solution. added 2 actions (for show , hide) , added there lines of code , works i'm not sure if that's correct way (and without using reducers, action - i'm new redux). i'm thinking way this: adding helper functions i'll have actions.refresh calls , importing them need access activitymodal visibility.

please tell me or suggest me correct way this?

thanks!


edit: succeeded i'd confirm if it's practice. here did:

containers/logincontainer.js

... this.props.showactivitymodal(); // calling on button press ... 

actions/activitymodal.js

... export function showactivitymodal() {   return {     type: types.activity_modal_show,     payload: {}   } } ... 

reducers/activitymodal.js

... return {    visible: true,    text: '' }; ... 

components/activitymodal.js

... class activitymodal extends component {    ...    componentwillreceiveprops(nextprops) {       this.setstate({         visible: nextprops.activitymodal.visible       })    }    ... }  function mapstatetoprops(state) {   return {     activitymodal: state.activitymodal   }; }  export default connect(mapstatetoprops)(activitymodal); 

thanks!

to wanted, had is:

function mapstatetoprops(state) {   return {     activitymodal: state.activitymodal   }; }  export default connect(mapstatetoprops)(activitymodal); 

to component wanted change state. , dispatch action change state of activitymodal.

i guess that's normal behavior react redux on wrong track when first started hey, figured out.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -