Answers for "react hooks examples"

15

state with react functions

class Example extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      count: 0
    };
  }

  render() {
    return (
      <div>
        <p>You clicked {this.state.count} times</p>
        <button onClick={() => this.setState({ count: this.state.count + 1 })}>
          Click me
        </button>
      </div>
    );
  }
}
Posted by: Guest on March-13-2020
0

react hooks demo

// Same basic function as in reactjs site, with a bit of improvement

import React, { useState, useEffect } from 'react';

export default function Homepage() {
  // Declare a new state variable, which we'll call "count"
    const [count, setCount] = useState(0);

    useEffect(() => {
        document.title = `You clicked ${count} times`;  
    })

  return (
    <div>
      <h2>You clicked {count} times!</h2>

      <button onClick={() => setCount(count > 0 ? count - 1 : count)}> Decrement </button>
      <button onClick={() => setCount(count + 1)}> Increment </button>
    </div>
  );
}
Posted by: Guest on August-15-2021
0

how to use hooks react

const App = () => {
const [students , setStudents] = useState([]);
  
  return (
// put in the jsx code here
  )
}
Posted by: Guest on April-26-2020

Browse Popular Code Answers by Language