Skip to content

Commit

Permalink
put hero image into its own component and set the random image in a s…
Browse files Browse the repository at this point in the history
…tate variable so it doesn't change on re-render (#1490)
  • Loading branch information
gumaerc authored Aug 30, 2024
1 parent 22450f6 commit 26beb71
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion frontends/mit-learn/src/pages/HomePage/HeroSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,15 @@ const getRandomHeroImage = () => {
return `/static/images/hero/hero-${imageNumber}.png`
}

const HeroImage: React.FC = () => {
const [heroImage, _] = useState(getRandomHeroImage)
return (
<ImageContainer>
<img alt="" src={heroImage} />
</ImageContainer>
)
}

const HeroSearch: React.FC = () => {
const [searchText, setSearchText] = useState("")
const onSearchClear = useCallback(() => setSearchText(""), [])
Expand Down Expand Up @@ -255,7 +264,7 @@ const HeroSearch: React.FC = () => {
</ControlsContainer>
</TitleAndControls>
<ImageContainer>
<img alt="" src={getRandomHeroImage()} />
<HeroImage />
</ImageContainer>
</HeroWrapper>
)
Expand Down

0 comments on commit 26beb71

Please sign in to comment.