BO41 is right, it is the font-awesome javascript that doesn't rerender. If you are okay with not using the new font-awesome svg/javascript icons, you can use font-awesome as a webfont with css.
In your index.html, delete the fontawesome script, and add the font-awesome css stylesheet:
<link href="https://use.fontawesome.com/releases/v5.0.2/css/all.css" rel="stylesheet">
Your code should work now.
The other possibility is to use the official font-awesome react package (it's a bit more of a hassle, but it uses the new svg icons)
Add necessary packages to project:
yarn add @fortawesome/fontawesome @fortawesome/react-fontawesome
yarn add @fortawesome/fontawesome-free-regular @fortawesome/fontawesome-free-solid
And the updated code:
import fontawesome from '@fortawesome/fontawesome'
import FontAwesomeIcon from '@fortawesome/react-fontawesome'
import { faCircle as fasCircle } from '@fortawesome/fontawesome-free-solid'
import { faCircle as farCircle } from '@fortawesome/fontawesome-free-regular'
const Circle = ({ filled, onClick }) => {
return (
<div onClick={onClick} >
<FontAwesomeIcon icon={filled ? farCircle : fasCircle}/>
</div>
);
};
class App extends React.Component {
state = { filled: false };
handleClick = () => {
this.setState({ filled: !this.state.filled });
};
render() {
return <Circle filled={this.state.filled} onClick={this.handleClick} />;
}
}
See the github repo for more information: https://github.com/FortAwesome/react-fontawesome
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…