mweststrate / use-st8

Single-function alternative for React.useState
MIT License
234 stars 7 forks source link

How to render when it is changed ? #6

Closed ZhangDaZongWei closed 4 years ago

ZhangDaZongWei commented 4 years ago

sorry, My English is not good, I want to ask a question:

const UseSt8Example: React.FC<any> = () => {
  console.log('running---1')   
  const count = useSt8(0)
  return (
    <>
      <span>{count()}</span>
      <button onClick={() => count(c => c+1)}>add</button>
    </>
  )
}

when click button, how count() to change ?

mweststrate commented 4 years ago

I don't get the question, that is what it does by default: https://codesandbox.io/s/q9q7yrxjkj