“Componentwillreceiveprops Hooks” Kode Jawaban

Componentwillreceiveprops Hooks

SomeComponent (props) => {

    useEffect( () => {
        console.log('someProp updated');
    }, [props.someProp])


    return <div>Hi {props.someProp}</div>
}
Tense Trout

Componentwillreceiveprops Hooks

const { useState, useEffect, useMemo } = React;

function App() {
  const [count, setCount] = useState(50);

  useEffect(() => {
    setTimeout(() => {
      setCount(150);
    }, 2000);
  }, []);

  return <DisplayCount count={count} />;
}

function DisplayCount(props) {
  const count = useMemo(() => props.count > 100 ? 100 : props.count, [props.count]);

  return <div> {count} </div>;
}

ReactDOM.render(<App />, document.getElementById("root"));
Restu Wahyu Saputra

Jawaban yang mirip dengan “Componentwillreceiveprops Hooks”

Pertanyaan yang mirip dengan “Componentwillreceiveprops Hooks”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya