tweakpane / use-tweaks

🎛️ Tweak React components with Tweakpane
https://codesandbox.io/s/use-tweaks-example-58e02
MIT License
768 stars 23 forks source link

Adds set and get initial tweaks data from the url hash #33

Open emmelleppi opened 3 years ago

emmelleppi commented 3 years ago

I added a couple of methods in utils.ts to set and get the initial schema values, based on the url hash

How to use it

  const { speed, factor } = useTweaks({
    speed: 1,
    factor: { value: 1, min: 10, max: 100 },
  }, { setGetFromUrl: true });

or

  const { speed } = useTweaks('Example', { speed: 1 }, { setGetFromUrl: true } )

If you set the setGetFromUrl value to true in the settings, the values are automatically set in the hash of the url when the changes occur.

When the component is mounted, the schema passed to the useTweaks hook is modified with the corresponding values found in the hash.

It is far from perfect and some TS types will certainly need to be fixed :)