Created
May 29, 2025 10:32
-
-
Save ruucm-working/ad8a0fdde38c5399b38d3b4e7c994862 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { forwardRef, type ComponentType } from "react" | |
import { createStore } from "https://framer.com/m/framer/store.js@^1.0.0" | |
// 공통 store 정의 | |
const useStore = createStore({ | |
count: 0, | |
}) | |
// 1. 버튼 클릭 시 count 증가 | |
export function clickButton(Component): ComponentType { | |
return forwardRef((props, ref) => { | |
const [store, setStore] = useStore() | |
return ( | |
<Component | |
ref={ref} | |
{...props} | |
onClick={() => { | |
setStore({ count: store.count + 1 }) | |
}} | |
/> | |
) | |
}) | |
} | |
// 2. 텍스트 컴포넌트에 count 표시 | |
export function displayCount(Component): ComponentType { | |
return forwardRef((props, ref) => { | |
const [store] = useStore() | |
return <Component ref={ref} {...props} text={String(store.count)} /> | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment