Answer the question
In order to leave comments, you need to log in
How to update styles of styled-components after request in API?
Hey!
I can not understand why the styles are not updated through styled-component
.
The code is this:
Parent, returns a list of elements during a request to the API:
class PokeCont extends Component {
shouldComponentUpdate(nextProps) {
if (this.props.pokemons !== nextProps.pokemons) {
return true;
}
}
render() {
return (
<PokeContainer>
{ this.props.pokemons.map(pokemon => <PokeCard key={pokemon.id} {...pokemon} />) }
</PokeContainer>
);
}
}
import { Name } from './styles/PokeStyles';
const PokeCard = ({id, name, type}) => {
return (
<Card>
<Name name={name}>
{name.toUpperCase()}
</Name>
</Card>
);
};
import styled from 'styled-components';
export const Name = styled.p`
border: 1px solid yellow;
background-color: ${(props) =>
props.name ? 'black' : 'pink'}
`;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question