Last active
October 5, 2020 14:24
-
-
Save itaditya/81427c47897456649310437ee895e7b3 to your computer and use it in GitHub Desktop.
(Blog) Testing a Redux hooked app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// App.js | |
function App() { | |
const stateAPIStatus = useLoadFoodData(); | |
return ( | |
<div className="food-app"> | |
<header> | |
<h1>Ordux</h1> | |
</header> | |
<Message status={stateAPIStatus} /> | |
</div> | |
); | |
} | |
// Comps.js | |
function Message(props) { | |
const { status } = props; | |
const messages = { | |
loading: 'Loading...', | |
error: ( | |
<> | |
Menu failed to load. | |
<br /> | |
Please try again... | |
</> | |
), | |
}; | |
const messageText = messages[status]; | |
if (!messageText) { | |
return null; | |
} | |
return ( | |
<div | |
className={`message-${status}`} | |
role={status === 'error' ? 'alert' : 'status'} | |
aria-live="polite" | |
aria-busy={status === 'loading'} | |
> | |
{messageText} | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment