Skip to content

Instantly share code, notes, and snippets.

@steveruizok
Created June 21, 2019 11:12
Show Gist options
  • Save steveruizok/f0f1237c0cb04d1001bbdc0a3e1eb326 to your computer and use it in GitHub Desktop.
Save steveruizok/f0f1237c0cb04d1001bbdc0a3e1eb326 to your computer and use it in GitHub Desktop.
Example Framer X code component that "shares" changes to its state through an event prop.
import * as React from "react"
import { Frame, FrameProps } from "framer"
type Props = Partial<FrameProps> & {
onValueChange: (value: number) => void
}
export function EventPropExample(props: Props) {
const { onValueChange, ...rest } = props
const [state, setState] = React.useState({
value: 0,
})
const handleTap = () => {
// Calculate the next value
const next = state.value + 1
// Share that value with the onValueChange event
onValueChange && onValueChange(next)
// Then update state
setState({
value: next,
})
}
return (
<Frame {...rest} onTap={handleTap}>
{state.value}
</Frame>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment