I learning redux right now, and i was making a project where i was doing a google oAuth authentication. so when i tried to use optional chaining operator i get this error.
You may need an appropriate loader to handle this file type.
| switch (_context.prev = _context.next) {
| case 0:
> result = res?.profileObj;
| token = res.tokenId;
and here is the code that is giving me the error
const googleSuccess = async (res) => {
const result = res?.profileObj;
const token = res?.tokenId;
try {
dispatch({ type: AUTH, data: { result, token } });
history.push('/');
} catch (error) {
console.log(error);
}
};
however if i remove the ?
the error goes away and it works fine.
i am using react-google-login npm package and the googleSuccess function is passed as a props to the GoogleLogin component.
if someone could clarify it to me. its just that sometimes, the value am assigning might not always be there and it may crash my app, and for that since optional chaining operator wasn't working i am using ternary operator(if the value to be assigned isn't present i am just assigning null
using ternary operator. (and am not sure if that is okie)).
apologies if this question is a newbie, i just wanted to clarify myself on why i cannot use ?. operator
because i couldn't find answers anywhere else. ps: today was the first time i was using ?.
operator
This is because webpack is not able to parse the file correctly because of the new syntax. If you have done the react-app setup from scratch using webpack . Then i suggest you to upgrade webpack . If you are using create-react-app , then you should upgrade to the latest version of CRA .