How do i retrieve values from payload object in react-native? -


i can't seem retrieve payload object contains snapshot.val() in reducer. below code

  1. profilefetch const in action class

    export const profilefetch = () => { //aysnc - use redux thunk const { currentuser } = firebase.auth(); return (dispatch) => { firebase.database().ref(/users/${currentuser.uid}/profile) .on('value', snapshot => { console.log('snapshot'); console.log(snapshot.val()); dispatch({ type: profile_fetch_success, payload: snapshot.val() }); actions.profileedit(); }); }; };

  2. below console.log view of snapshot.val() . want retrieve content in bold below.

    object -kgjklkmrjajijdu2gr3 : object address1 : "1234" address2 : "4567" email : "test@test.com" firstname : "lim" lastname : "bee teck" mobile : "933445566" postalcode : "7890" proto : object proto : object

  3. below reducer

    export default (state = initial_state, action) => { switch (action.type) { case profile_fetch_success: return action.payload; default: return state; } };

    1. below component. not able see values in payload @ when below form renders when action -> reducer -> form renders. advice appreciated. tks !

    import _ 'lodash'; import react, { component } 'react'; import { connect } 'react-redux'; import { card, cardsection, button } './common'; import profileform './profileform'; import { profileupdate, profilesave } '../actions';

    class profileedit extends component {

    componentwillmount() { _.each(this.props.profile, (value, prop) => { this.props.profileupdate({ prop, value }); }); } onbuttonpress() { const { firstname, lastname, email, address1, address2, postalcode, mobile } = this.props; //console.log(name, phone, shift); this.props.profilesave({ firstname, lastname, email, address1, address2, postalcode, mobile, uid: this.props.profile.uid }); }

    render() { return ( save changes ); } } const mapstatetoprops = (state) => { const { firstname, lastname, email, address1, address2, postalcode, mobile

        } = state.profileform; 

    return { firstname, lastname, email, address1, address2, postalcode, mobile }; };

    export default connect(mapstatetoprops, { profileupdate, profilesave })(profileedit);


Comments