bartonhammond/snowflake

Trying to use redux state this.props.global.currentUser in app.js

Closed this issue · 7 comments

In app.js, the render function is as follows:

render () {
let component = ;
if (this.state.loggedIn) {
component = ;
}
return (
component
);
}
});

When the if expression (this.state.loggedIn) becomes true I would like to be able to use the contents of the redux state this.props.global.currentUser. However, this.props.global.currentUser is 'undefined' at this point. The reason why I'd like to use currentUser is because I've added a "userType" field within the global.currentUser state, but for some reason, this state is not preserved. My goal is for app to render a different component to render depending on the value of userType.

Barton, can you clarify whether this.props.global.currentUser is meant to be used in the way that I'm attempting?

Thanks!

hi @wookiem

If you look at Profile.js you'll see the getProfile call - the profile isn't needed until the Profile page is rendered, i.e, the global.currentUser is not available at the App.

  componentDidMount() {
    if (this.props.profile.form.fields.username == '' && this.props.profile.form.fields.email == '') {
      this.props.actions.getProfile(this.props.global.currentUser); ///<<<<<<<<<<<<<<<
    } else {
      this.setState({
        formValues: {
          username: this.props.profile.form.fields.username,
          email: this.props.profile.form.fields.email
        }
      });
    }      
  }

If you need to get the global.currentUser you could look at storing it when the Login/Registration is successful. You could just put it into the local storage so that AppAuthToken can retrieve it too

Hi Barton. I was able to fold in a couple small changes that make this.props.global.currentUser available in the app module. Based on how globalReducer was trying to handle the LOGIN_SUCCESS case, I think that these changes are consistent with your original intent. I've issued a pull request since I think these changes may benefit others.

Thanks for the PR @wookiem

Hi @wookiem
I have the same issue that i am trying to get the value from global.currentUser. I created a new column on User name avatarfile. I can see from the JSON log header.
However, i am no ideas how to parse that to field that i wanted.

Thank you.

Hi @myujang

I had to make changes to quite a few Snowflake files in order to add support for additional fields within currentUser. I'm currently away from my development environment, so I can't even tell you which files I touched. Let me know if you are still interested and I will compile the list of files (I'm back tomorrow).

Hi @wookiem
Thank you very much. I am interested to know. I am more on exploring React Native. Start learning JavaScript. I think @bartonhammond done very good boilerplate for learning React Native.

Hi @myujang

I've run the diff command in MacOS terminal to highlight the changes that I made to Snowflake. I can't guarantee that I extracted everything perfectly, but it should give you a pretty good sense of the changes you'll need to make for your specific customizations.

In my case, I wanted to use the user's email as the Parse username, so I dropped username from the registration and login forms. On the other hand, I do need the user to enter their first and last names. So, I had to create these "columns" in Parse in addition to enabling these fields in Snowflake's registration and login forms.

Hope this helps.

compare.pdf