Change Navbar background-color on scroll in ReactJS

Viewed 358

I have following ReactJS code, which work in this way. In scrolling 30px it change header background color on blue and in returning on 0px it became transparent. I think it working good. But my problem is in another thing. I want only it work on my home page ("/"). How can I achieve it?

My COde

I try this

    backgroundColor: change && useLocation().pathname == "/" ? "blue" : "transparent"

But it's not help me.

In other cases("), as it was originally, let it remain. Please, I need help.

1 Answers

I think you just need

backgroundColor: useLocation().pathname === "/" && change ? "transparent" : 'blue',

Related