Skip to content

Instantly share code, notes, and snippets.

@vhuerta
Created March 7, 2020 19:36
Show Gist options
  • Save vhuerta/4be62975a261b78f10b06b964f2b4737 to your computer and use it in GitHub Desktop.
Save vhuerta/4be62975a261b78f10b06b964f2b4737 to your computer and use it in GitHub Desktop.
import * as React from "react";
import { usePokemonReducer, fetchPokemons } from "./pokemon.ducks";
export default function App() {
const [state, dispatch] = usePokemonReducer();
function handleOnClick() {
dispatch(fetchPokemons());
}
return (
<div className="App">
<h1>Hello Reducer Thunks and Ducks!</h1>
<button onClick={handleOnClick} disabled={state.isLoading}>
{state.isLoading ? "Fetching pokemons..." : "Fetch pokemons"}
</button>
<ul style={{ listStyle: "none" }}>
{state.pokemons.map(pokemon => (
<li key={pokemon.name}>
<a href={pokemon.url}>{pokemon.name}</a>
</li>
))}
</ul>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment