Answers for "usestate react documentation"

9

reactjs useState() hook

import React, { useState } from 'react';

function Example() {
  // Declare a new state variable, which we'll call "count"  
  const [count, setCount] = useState(0);
  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={() => setCount(count + 1)}>
        Click me
      </button>
    </div>
  );
}
Posted by: Guest on September-08-2020
0

react usestate nedir

import { useState, useEffect } from 'react';

function ArkadasDurumu(props) {
  const [onlineMi, onlineDurumuAta] = useState(null);

  function handleDurumuDegistir(durum) {
    onlineDurumuAta(durum.onlineMi);
  }

  useEffect(() => {
    ChatAPI.arkadasDurumunaAboneOl(props.arkadas.id, handleDurumuDegistir);

    return () => {
      ChatAPI.arkadasDurumuAboneligindenCik(props.arkadas.id, handleDurumuDegistir);
    };
  });

  if (onlineMi === null) {
    return 'Yükleniyor...';
  }
  return onlineMi ? 'Online' : 'Offline';
}
Posted by: Guest on October-26-2021

Browse Popular Code Answers by Language