Created
June 21, 2019 11:12
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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