Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to compose on functional components (without export default) #29

Closed
sebmaz93 opened this issue Nov 26, 2018 · 3 comments
Closed

how to compose on functional components (without export default) #29

sebmaz93 opened this issue Nov 26, 2018 · 3 comments

Comments

@sebmaz93
Copy link

sebmaz93 commented Nov 26, 2018

I have components which exports multi functions , i tried many ways to compose this on them but non worked , if anyone can help will appreciate that.
here is sample of my code (there are x3 like this one)

export const login = creds => {
  return async () => {
    const firebase = getFirebase();
    try {
      await firebase.auth().signInWithEmailAndPassword(creds.email, creds.password);
    } 
catch (error) {
      console.log(error);
      });
    }
  };
};

how can make enqueueSnackbar works here ?

@iamhosseindhv
Copy link
Owner

I'm not sure if I followed @TITAN9389, but if you don't have access to props, you can return a promise and resolve on successful sign in, and .then call enqueueSnackbar.

I'm sure I can help more if you provide a codesandbox example.

@sebmaz93
Copy link
Author

I'm not sure if I followed @TITAN9389, but if you don't have access to props, you can return a promise and resolve on successful sign in, and .then call enqueueSnackbar.

I'm sure I can help more if you provide a codesandbox example.

its a little bit complicated to make a sample on sandbox ,i got your point about returning promise i'll try and see if i'll need further help will tell, thanks.

@iamhosseindhv
Copy link
Owner

I'm closing this but let me know if there was a problem.

login = () => (
       new Promise((resolve) => {
            const firebase = getFirebase();
            try {
                await firebase.auth().signInWithEmailAndPassword(creds.email, creds.password);
                resolve()
            } 
            catch (error) {
                console.log(error);
            }
      });
);
// in your component
login().then(() => this.props.enqueueSnackbar(...))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants