Skip to main content

Core API for React

useMutable

import { useState } from 'react'
import { useMutable } from 'reev/react'

export const App = () => {
const [i, set] = useState(0)
const { click } = useMutable({ click: () => set(i + 1) })
return <button onClick={click}>{i}</button>
}

useEvent

import { useState } from 'react'
import { useEvent } from 'reev/react'

export const App2 = () => {
const [i, set] = useState(0)
const e = useEvent({ click() {} }) // do something when component will be clicked
e('click', () => set((p) => p + 1)) // register new function
return <button onClick={e.click}>{i}</button>
}

useRefEvent

import { useRefEvent } from 'reev/react'

export const App3 = () => {
const [i, set] = useState(0)
const event = useRefEvent({
mount() {}, // do something when component did mount
clean() {}, // do something when component did unmount
click() {}, // do something when component will be clicked
})
event('click', () => set((p) => p + 1)) // register new function
return (
<button ref={event.ref} onClick={event.click}>
{i}
</button>
)
}