Skip to content

Instantly share code, notes, and snippets.

@koenbok
Created May 23, 2022 14:47
Show Gist options
  • Save koenbok/09785fd0aa6c7449561bc5927ef7aaeb to your computer and use it in GitHub Desktop.
Save koenbok/09785fd0aa6c7449561bc5927ef7aaeb to your computer and use it in GitHub Desktop.
import type { ComponentType } from "react"
import { createStore } from "https://framer.com/m/framer/store.js@^0.3.0"
const useStore = createStore({ count: 0 })
export const withCount = (Component): ComponentType => {
return (props) => {
const [store, setStore] = useStore()
return <Component {...props} text={`${store.count}`} />
}
}
export const withIncrement = (Component): ComponentType => {
return (props) => {
const [store, setStore] = useStore()
const onTap = () => setStore({ count: store.count + 1 })
return <Component {...props} onTap={onTap} />
}
}
@andipollokhfg
Copy link

andipollokhfg commented Jun 8, 2023

Using this code worked in preview, but not when publishing the site.

Updating store.js to 1.0.0 fixed that:
import { createStore } from "https://framer.com/m/framer/store.js@^1.0.0"

Thanks to Sakibul Islam for the solution (https://www.framer.community/c/developers/store-not-working-on-published-site).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment