Skip to content

Instantly share code, notes, and snippets.

@BrianJenney
Created November 28, 2021 14:20
Show Gist options
  • Save BrianJenney/59122a03111a499ccda2d091beee2117 to your computer and use it in GitHub Desktop.
Save BrianJenney/59122a03111a499ccda2d091beee2117 to your computer and use it in GitHub Desktop.
const ShoppingCart = () => {
const [errorMessage, setErrorMessage] = useState(null)
const isLoggedIn = useSelector((state) => state.account.isLoggedIn);
const urlToUse = isLoggedIn ? 'https://api/customercheckout' : 'https://api/guestcheckout';
const addToCartFunction = async (items) => {
const { data, errors } = await axios.post(urlToUse, {items});
if(errors){
setErrorMessage('Oops, something went wrong...')
}
}
return ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment