useState

Allows you to create a reactive state variable within a component. Changes will trigger re-renders of the component to reflect the updated state.

Example

import { useState } from "kaioken"

function App() {
  const [count, setCount] = useState(0) // Initial state is 0

  const handleClick = () => {
    setCount((prev) => prev + 1) // Update state using setCount
  }

  return (
    <div>
      <p>You clicked {count} times</p>
      <button onclick={handleClick}>Click me</button>
    </div>
  )
}

Related