LINUX.ORG.RU

История изменений

Исправление moot, (текущая версия) :

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

export default function App() {
  const [counter, setCounter] = useState(0);

  const increaseCounter = useCallback(
    () => setCounter(counter + 1),
    [counter, setCounter]
  );

  return (
    <button onClick={increaseCounter}>
      Count: {counter}
    </button>
  );
}

Исправление moot, :

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

export default function App() {
  const [counter, setCounter] = useState(0);

  const increaseCounter = useCallback(
    () => setCounter(counter + 1),
    [counter, setCounter]
  );

  const decreaseCounter = useCallback(
    () => setCounter(counter - 1),
    [counter, setCounter]
  );

  return (
    <button onClick={increaseCounter}>
      Count: {counter}
    </button>
  );
}

Исходная версия moot, :

React

import React, { useState, useCallback } from 'react'

export default function App() {
  const [counter, setCounter] = useState(0);

  const increaseCounter = useCallback(
    () => setCounter(counter + 1),
    [counter, setCounter]
  );

  const decreaseCounter = useCallback(
    () => setCounter(counter - 1),
    [counter, setCounter]
  );

  return (
    <button onClick={increaseCounter}>
      Count: {counter}
    </button>
  );
}