“React JS accessoires” Réponses codées

Les accessoires en classe réagissent

class MouseTracker extends React.Component {
  constructor(props) {
    super(props);
    this.handleMouseMove = this.handleMouseMove.bind(this);
    this.state = { x: 0, y: 0 };
  }

  handleMouseMove(event) {
    this.setState({
      x: event.clientX,
      y: event.clientY
    });
  }

  render() {
    return (
      <div style={{ height: '100vh' }} onMouseMove={this.handleMouseMove}>
        <h1>Move the mouse around!</h1>
        <p>The current mouse position is ({this.state.x}, {this.state.y})</p>
      </div>
    );
  }
}
Beast

passer les accessoires dans réagir

/* PASSING THE PROPS to the 'Greeting' component */
const expression = 'Happy';
<Greeting statement='Hello' expression={expression}/> // statement and expression are the props (ie. arguments) we are passing to Greeting component

/* USING THE PROPS in the child component */
class Greeting extends Component {
  render() {
    return <h1>{this.props.statement} I am feeling {this.props.expression} today!</h1>;
  }
}
CodeHelper

Exemple d'accessoires dans React

const Banner = props => {
  const name = props.name
  return <div>Hello {name}</div>
}

function App() {
  return (
    <div>
      <Banner name="Ranjeet" />
    </div>
  )
}

export default App
Outrageous Ostrich

React JS accessoires

function App() {
  return (
    <div className="App">
      <NewComponent name="Ariful Islam Adil" profession="Web-Developer"></NewComponent>
    </div>
  );
}

function NewComponent(props) {
  return (
    <div className="test-class">
      <h1>Name: {props.name}</h1>
      <h3>Profession: {props.profession}</h3>
    </div>
  )
}
export default App;
Ariful Islam Adil(Code Lover)

Utilisation d'accessoires avec React: avec des accessoires


function App() {

return(
<>

<Abc/>
<Abc x="xxxxx"/>
    </>
  );
}

export default App;


function Abc(props)
{
return (<>{props.x?<b>ffffff</b>:<i>gggggg</i>}</>)
}
/*Abc depends on the value of the x prop*/
Javasper

accessoires

class Checkbox extends React.Component {
  constructor(props) {
    super(props);
    this.state = { isOn: true };
  }
  // ...
}
Doubtful Dingo

Réponses similaires à “React JS accessoires”

Questions similaires à “React JS accessoires”

Plus de réponses similaires à “React JS accessoires” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code