Question:
here’s the jist of where I’m stuck (or just read the title for my question).I have a
firebase.js
file where I have functions to authenticate. signinGithub
, signinGoogle
, signinEmail
and so forth. The Firebase Auth business logic is in these functions.I am showing errors with
console.log
or alert
from these functions. The functions are imported into a Component
and I don’t know how to capture the functions result into the component by somehow setting state from this out-of-component function file.Here’s a basic example:
firebase.js
- Set state in Login.js
const [message, setMessage] = useState('')
- When the imported signinWithGitHub has an
error
message —
I’m stuck figuring out how to apply to function message to the state, any ideas?
Answer:
You can create a custom function inside yourLogin. jsx
file to call the original signInWithGitHub
method with a try
catch
block. And more importantly, you should not use render
inside a functional component. Use return
to render the JSX
in DOM.
firebase.js
Login.jsx
If you have better answer, please add a comment about this, thank you!