question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handling multiple instances of a component with tweaks

See original GitHub issue

Hey! Love the library 😃

I have multiple instances of a component with a useTweaks call, say:

const Button = ({ text }: { text: string }) => {
  const { color } = useTweaks("Buttons", { color: "blue" });

  return <button style={{ backgroundColor: color }}> {text} </button>
}

However, every single instance Button will add its own color setting in the tweakpane, whereas my intent was to have them all share the same value. My question: should I just hoist the useTweaks call up one level and pass the tweaked value down as a prop (feels kind of meh)? Or is there a nicer solution to this? I tried passing the same presetKey but they still have different tweakpane inputs. Here’s a sandbox demonstrating the “issue”: https://codesandbox.io/s/gracious-bas-22vg2?file=/src/App.tsx.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

4reactions
dbismutcommented, Nov 10, 2020

Hi @Pocket-titan we got pumped and decided to rewrite something from scratch, that fits React and supports your idea out of the box with no major hassle.

useTweaks({ color: 1, number: 4 }, folder("sub", { a: 2, b: 3 }, folder("sub2", { c: 4 })))

You’ll also be able to do:

useTweaks("sub.sub2", { c: 4 })

And get the value. Of course the value will only be initialized once (by the first hooks that gets called).

We’ll try to release something in alpha as soon as it’s usable.

PS: the idea is to store the data structure but flatten. So that the store looks like:

{
  "valueKey": value
  "folder.subfolder.valueKey": value
  // ...
}
1reaction
gsimonecommented, Nov 10, 2020

If anybody comes across this and wants to try alphas of the new version, drop me a DM on twitter or an email!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling multiple instances of a component with tweaks #36
Hey! Love the library :) I have multiple instances of a component with a useTweaks call, say: const Button = ({ text }:...
Read more >
Coding Militia | Episode 028 - ASP.NET Core: From 0 to overkill
One important scenario to consider, is having multiple instances of each component running in parallel. It's a very important topic to consider, ...
Read more >
Placing multiple Instances of a component at once
Solved: Hello everyone, I use a "dump assembly" of assemblies to create cut lists. I throw in multiple copies of each assembly for...
Read more >
Top 7 Tweaks and Tricks to Improve React Performance
1. Troubleshooting the redundant rerender · 2. Reducing the rerender by splitting the component · 3. What is instance re-creation and how to...
Read more >
java - Multiple components deployed to same application server
In general it's not an issue to have multiple instances of any module ... You can probably tweak the JVM settings to handle...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found