With regard to React

Asked

Viewed 32 times

-2

I have a question about react, i wanted to change the content of the page by clicking, but the site recognizes only as Object.

Function

import React from 'react';   

//funções 
export  function botao2(){
    document.querySelector('.CassandraText').innerHTML = 'Downloading Cassandra';
    document.querySelector('.resumo').innerHTML = <h3>Latest Beta Version</h3>;
    console.log('clicado');
}

The button that calls the function

<button onClick={botao2}> 
    Download Cassandra
</button>

In case I was trying to open the <h3>, but when I send to component, he appears as object.

  • Don’t try using React, if it’s new, learn Javascript, HTML, and CSS, then you can try going to React or another library/framework

1 answer

0

You have to give a studied how it works , the way to change screens, variables, etc. Really before entering the world give a studied in , and at least the basic not to get lost in it.

When creating a component in React to change contents follows a minimum example:

function App() {
  const [nome, setNome] = React.useState('Inicial');
  return (
    <div>
      <h3>{nome}</h3>
      <button
          onClick={e => 
            setNome('Alterado com sucesso')}
       >Alterar</button>
    </div>
  )
}

ReactDOM.render( <App/> , document.getElementById('root'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.8.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.8.3/umd/react-dom.production.min.js"></script>
<div id="root">Carregando ...</div>

And so begins to use and the central idea of how to change page contents.

  • hard is that I want to change the tag of another component, which is not that of the button.

  • It would have a way to use the query selector to add these tags?

  • It is not with querySelector that does this, React is a specific way to create components, I gave you an example, the big problem was that your question does not have a specific focus and you want to mix things ... ! React has to be done in his little world! with his functions and characteristics ... @use

  • o duro é que eu quero alterar a tag de outro componente, que não é esse do botão be specific, the example is to create a reality you did not know, but, this is how it should be done, now do not know well your problem could explain?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.