anotherRandomGuy
anotherRandomGuy

Reputation: 11

React native questions

I am very new to react native but wish to create a mobile application, I have a couple of questions which I would be very grateful if someone could please help.

Firstly A question about authentication. This boggles my mind completely.

In my application I would like the end user to be able to authenticate via both Google and Facebook, but I don't understand how these link to the same account in the backend

For example, User A firstly logs into app using google, uses it for a while. They then log out and re-authenticate with facebook, this links them to the first login with Google. How? When I auth with both Google and Facebook I see nothing that links them other than their name and sometimes email address, Am I missing something? how would I allow authentication with both that would then point to same point at backend?

Secondly I am using redux for managing my states.

when I load up my state is it ok to do the following

componentWillMount(){
  this.state = this.props.reducerState
}

then if I dispatch an action to update the reducer would the state update automatically, or is this the wrong approach, I just don't know exactly what to do as I have a file with my states in, should I be importing that to the component directly?

Because I was reading updating props doesn't init an re-render of component. I would really need a component to update when an action is called and the redux state changes.

thanks guys

Upvotes: 0

Views: 61

Answers (2)

Pooja Biradar
Pooja Biradar

Reputation: 11

By default, this runs after each render and every update so every time you change the state the componentWillMount calls fire so you have to pass an empty array in the end. It will only fire once on the first render. you also can pass the name of the variable of state in the array.

class Content extends React.Component {
componentWillMount(()=>{
this.state = this.props.reducerState
}, []);
} 


   
   

Upvotes: 1

Reema
Reema

Reputation: 83

  1. Update State on prop change (i.e, reducer change in your terms)

For this, the latest approach is to use getDerivedStatefromProps. We can use like

 class Example extends Component
{
 constructor(props) {
    super(props);
    this.state = {
     data:[]
    };
  }
static getDerivedStateFromProps(nextProps, prevState) {
 return {
  data: nextProps.data_prop,
 };
}
-
-
-
}

Here data is state and data_prop is the reducer variable. This method will only invoke when there is update in the data_prop.

Upvotes: 0

Related Questions