I want you to act as a Senior Frontend developer. I will describe a project details you will code project with this tools: Create React App, yarn, Ant Design, List, Redux Toolkit, createSlice, thunk, axios. You should merge files in single index.js file and nothing else. Do not write explanations. My first request is Create Pokemon App that lists pokemons with images that come from PokeAPI sprites endpoint

回复样本
Sure, here's the code for the Pokemon App: ```javascript import React, { useEffect } from 'react'; import { useSelector, useDispatch } from 'react-redux'; import { List } from 'antd'; import { createSlice, configureStore, createAsyncThunk } from '@reduxjs/toolkit'; import axios from 'axios'; const pokemonSlice = createSlice({ name: 'pokemon', initialState: { pokemons: [], status: 'idle', error: null }, reducers: {}, extraReducers: (builder) => { builder .addCase(fetchPokemons.pending, (state) => { state.status = 'loading'; }) .addCase(fetchPokemons.fulfilled, (state, action) => { state.status = 'succeeded'; state.pokemons = action.payload; }) .addCase(fetchPokemons.rejected, (state, action) => { state.status = 'failed'; state.error = action.error.message; }); }, }); const fetchPokemons = createAsyncThunk('pokemon/fetchPokemons', async () => { const response = await axios.get('https://pokeapi.co/api/v2/pokemon?limit=20'); return response.data.results; }); const store = configureStore({ reducer: pokemonSlice.reducer, }); function App() { const dispatch = useDispatch(); const pokemons = useSelector((state) => state.pokemons); useEffect(() => { dispatch(fetchPokemons()); }, [dispatch]); return ( <List dataSource={pokemons} renderItem={(pokemon) => ( <List.Item> <List.Item.Meta title={pokemon.name} avatar={<img src={pokemon.sprites.front_default} alt={pokemon.name} />} /> </List.Item> )} /> ); } export default App; ``` Note: The code assumes that you have already installed the necessary dependencies and set up the project using `Create React App` with `yarn`, `Ant Design`, and `axios`.
出版日期: 1 年前