Answer the question
In order to leave comments, you need to log in
How to remember the value of a variable so as not to cause an effect on mounting and remounting?
Good afternoon. If the url contains the name of the pokemon, then the application renders the detail view component.
app.js
import React from 'react';
import { Route } from 'react-router-dom';
import Header from './components/Header/Header';
import Pokedex from './components/Pokedex/Pokedex';
import PokePage from './components/PokePage/PokePage';
const App = () => (
<React.Fragment>
<Header />
<Route exact path="/pokedex/">
<Pokedex />
</Route>
<Route path="/pokedex/:pokeName">
<PokePage /> // страница детального просмотра покемона
</Route>
</React.Fragment>
);
export default App;
import React, {useEffect} from 'react';
import { useDispatch, useSelector } from 'react-redux';
import {useParams} from 'react-router-dom';
import {Container} from '@material-ui/core';
import {fetchPokemonByName} from "../../redux/PokeDetail/operations";
import pokeDetailSelectors from "../../redux/PokeDetail/selectors";
const mapState = (state) => ({
pokemon: pokeDetailSelectors.getPokemon(state),
error: pokeDetailSelectors.getError(state),
});
const PokePage = () => {
const { pokeName } = useParams();
const dispatch = useDispatch();
const {pokemon, error} = useSelector(mapState);
useEffect(() => {
dispatch(fetchPokemonByName(pokeName));
}, [pokeName]);
return (
<React.Fragment>
<Container maxWidth="lg">
<h1>Detail page in dev process</h1>
Pokemon name: {pokeName}
</Container>
</React.Fragment>
);
};
export default PokePage;
Answer the question
In order to leave comments, you need to log in
You can't say to a dying component: Pass this on to the next generation.
Since there is already an editor, you can organize data caching on it. When dispatching, check the availability of data in the cache, their freshness. No - we went for the data, put it in the cache. Yes - we do nothing, the select component will pull them out anyway.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question