Skip to content

Instantly share code, notes, and snippets.

@itaditya
Last active October 5, 2020 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itaditya/81427c47897456649310437ee895e7b3 to your computer and use it in GitHub Desktop.
Save itaditya/81427c47897456649310437ee895e7b3 to your computer and use it in GitHub Desktop.
(Blog) Testing a Redux hooked app
// 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