0

I want to change the opacity and pointer-events of two elements when i click another element, i searched and i was able to change the opacity using a const for the style and setState (which i dont really understand fully yet) but its a hard no on the pointer-events. I ended up writing in JQuery so you understand better what i want to do.

const App = () => {

  const iluminar = () => {
    $('#oscurecido').css("opacity", 0);
    $('#oscurecido').css("pointer-events", "none");
    $('#sesion').css("opacity", 0);
    $('#sesion').css("pointer-events", "none");
  }

  return (
    <div className="App">
      <div id="oscurecido" onClick={iluminar}></div>
      <Router>
        <Nav/>
        <Switch>
          <Route path="/" exact component={Productos}/>
          <Route path="/Carrito" exact component={Carrito}/>
          <Route path="/" component={Err}/>
        </Switch>
      </Router>
      {true ? <Sesion/> : null}
    </div>
  )
}
2
  • 1
    You really shouldn't combine between jQuery and react. This is really a bad practice. Commented Apr 8, 2020 at 23:39
  • Check out CLSX: github.com/lukeed/clsx#readme Commented Apr 9, 2020 at 0:03

1 Answer 1

2

What you should do is create a class with all the css code you want to apply to it onClick. Then you create a state with default value to false and onClick you ser it to true. Assign that class if the state is true.

.some-class { ...css properties }


const App = () => {
const [ iluminated, setIluminated ] = useState(false)

return (
<div className="App">
  <div id={iluminated ? 'some-class' : ''} onClick={() => setIluminated(true)}></div>
  <Router>
    <Nav/>
    <Switch>
      <Route path="/" exact component={Productos}/>
      <Route path="/Carrito" exact component={Carrito}/>
      <Route path="/" component={Err}/>
    </Switch>
  </Router>
  {true ? <Sesion/> : null}
</div>

) }

Sign up to request clarification or add additional context in comments.

1 Comment

If that was helpful I would apreciate if you mark the answer as correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.