Link Diary June 2023

Check the HTTP/2 capability of your website

What PC GPU can be compared to the Steam Deck?

React may execute a state update twice

To annoy the developer to make the function pure.

https://react.dev/reference/react/useState#my-initializer-or-updater-function-runs-twice

Will go wrong with the toggle inside the function:

  const [grid, setGrid] = useState([
    ['', '', ''],
    ['', '', ''],
    ['', '', '']
  ]);
  const handleClick = (row, col) => {
  
    // this lambda function is not pure
    setGrid(prevGrid => {
      const newGrid = [...prevGrid];
      newGrid[row][col] = '';
      if(prevGrid[row][col] !== 'yellow') {
        newGrid[row][col] = 'yellow';
      }
      return newGrid;
    });
  };

Fixed by calculating the value outside of the function:

  // ...
  const handleClick = (row, col) => {
    let newValue = '';
    if(grid[row][col] !== 'yellow') {
      newValue = 'yellow';
    }
    setGrid(prevGrid => {
      console.log(row, col);
      const newGrid = [...prevGrid];
      newGrid[row][col] = newValue;
      return newGrid;
    });
  };

Video Picks

Youtube Preview/Vorschau

That hurts

Youtube Preview/Vorschau

Human brain merges in rat

Youtube Preview/Vorschau

Visuals of a mushroom trip

Youtube Preview/Vorschau

Bilingual superpower

Youtube Preview/Vorschau

The Ninja Turtles Story

OEmbed Error
  • Provider returned HTTP Status 404 for
  • All resolution methods failed

Squirrel issues

Youtube Preview/Vorschau

Language learning mastermind

Youtube Preview/Vorschau

RANCID history

Youtube Preview/Vorschau

Top 100 Linux commands

Youtube Preview/Vorschau

Mouse Maze Innovations

Youtube Preview/Vorschau

deltaTime elaboration

Youtube Preview/Vorschau

RANCID japan fan service

Youtube Preview/Vorschau

Matt Freeman best unk bass player

Youtube Preview/Vorschau

Super rare RANCID bootleg

Youtube Preview/Vorschau

Snoop's reaction to his butchered song

Youtube Preview/Vorschau

Rowan Atkinson on free speech

Youtube Preview/Vorschau

Wise money advice

Youtube Preview/Vorschau

Blender Short clip making of

Discussion

Enter your comment: