Hillary Chege
Crafting Digital Excellence

Code Snippets

Useful code examples and solutions I've collected. Feel free to use and learn from them!

react_usestate_hook.js ×

// React useState Hook

// Managing state in functional components

import React, { useState } from 'react';

function Counter() {
  const [count, setCount] = useState(0);

  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={() => setCount(count + 1)}>
        Increment
      </button>
      <button onClick={() => setCount(count - 1)}>
        Decrement
      </button>
    </div>
  );
}

export default Counter;