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.

Proposal: render the UI conditionally

See original GitHub issue

Sometimes, it is useful to show the pane conditionally, while everything works the same. In my case, I need to show the pane only to designers and not the client. I achieve this via a special url, and I have a check like

export const DEBUG = window.location.search.includes('?debug')

which check if ?debug is appended to the url.

WIth use-tweaks, we achieved this with a really dirty useTweaksOnDebug:

const getValuesFromTweaks = (...args: any[]) => {
  const obj = typeof args[0] === 'object' ? args[0] : args[1]

  const getEntries = (obj: any): any => {
    return Object.keys(obj).flatMap((k) => {
      const v = obj[k]

      if (v.type !== undefined) {
        if (v.type === 1) {
          // Folder
          return getEntries(v.schema)
        } else {
          // Button or Separator
          return []
        }
      } else {
        return [[k, v.value ?? v]] // array of tuple because of flatmap
      }
    })
  }

  return Object.fromEntries(getEntries(obj))
}

export const useTweaksOnDebug: typeof useTweaks = DEBUG ? useTweaks : getValuesFromTweaks

I don’t know how the API of this would look like if we plan to remove the <Twix> component, any solution is appreciated.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
dbismutcommented, Feb 11, 2021

Great! Should be fixed by a7ce7fc, sorry for not making a PR!

1reaction
gsimonecommented, Dec 23, 2020

IMO this is important - and easy - enough to be req for v1

Read more comments on GitHub >

github_iconTop Results From Across the Web

7 Ways to Implement Conditional Rendering in React ...
Conditional rendering is a term to describe the ability to render different user interface (UI) markup if a condition is true or false....
Read more >
Conditionally render ui:define - jsf - Stack Overflow
The <ui:insert> runs during view build time, so it's not possible to conditionally render it by a property which is set via <f:viewParam>...
Read more >
How do you do conditional rendering in React?
You can use conditional rendering to see whether the object you have fetched is available for rendering. Otherwise, do not render the object....
Read more >
Conditional Rendering - React
Use JavaScript operators like if or the conditional operator to create elements representing the current state, and let React update the UI to...
Read more >
5 simple way for conditional rendering in JSX - DevDojo
With React, we can create powerful web applications that provide state of the art UI and a high level of interactivity.
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