1

I need to pass a function on the props. I have this component:

import React, {Component} from 'react';
import { View } from 'react-native';
import {FBLogin, FBLoginManager} from 'react-native-facebook-login';

const Loginfb = (props) => (
        <FBLogin
        style={{marginBottom: 10}}
        ref={props.ref}
        permissions={["email", "user_friends"]}
        loginBehavior={FBLoginManager.LoginBehaviors.SystemAccount}
        onLogin={props.login}
);

export default Loginfb;

Where props.ref and props.login are functions with data. In my container component I have this:

import React, {Component} from 'react';
import {View} from 'react-native';
import {FBLogin, FBLoginManager} from 'react-native-facebook-login';
import Loginfb from '../components/fblogin';

class Inicio extends Component {

constructor(props) {
  super(props);
  this.state = {
    user: null,
  };
}

Ref = (fbLogin) => {
  this.fbLogin = fbLogin
}

login = (data) => {
  console.log("Logged in!");
  console.log(data);
  this.setState({user: data.credentials});
}

render() {
     return (
        <View
             <Loginfb
              ref={this.ref} 
              onLogin={this.login}/>
        </View>
              );
       }
}
export default Inicio;

I can't understand my error: "this.props[event] is not a function"

Please Help.

2
  • Try <Loginfb ref={this.ref} login={this.login} /> in your container. Commented Aug 11, 2017 at 5:28
  • I tried, but the error continue Commented Aug 11, 2017 at 5:46

1 Answer 1

1

Not quite sure, but I'm assuming the context is lost.

Either inline when you pass them to the child: myFunction.bind(this)

Or in the constructor of the container, like so:

this.myFunction = this.myFunction.bind(this)

Hope this helps.

Sign up to request clarification or add additional context in comments.

2 Comments

In the child can be props.login.bind(this) ?
Did this work for you @HernanHumaña? Maybe you can approve the answer so others know it helped :) Cheers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.