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.

dynamic update component in playground?

See original GitHub issue

Is it possible to dynamic update a component in Playground?

Description I would like to have a working example in the Playground. In my case I have a toggle component and I want to change the status of the selection when the user clicks the component

name: UIToggle
menu: Components

import { Playground, PropsTable } from 'docz'
import UIToggle  from './index.js'
let isToggled = true;
const _onToggleStateChange = () => {
  console.log(isToggled);
  isToggled = !isToggled;
}

# UIToggle

Hello, I'm still a mdx file, but now I have a button component!


<PropsTable of={UIToggle} />

<Playground>
    <UIToggle isToggled={isToggled} onToggle={ _onToggleStateChange } ></UIToggle>
</Playground>

This is my code. The variable isToggled is updated when the user clicks, but the components don’t receive any update.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
rakannimercommented, Aug 14, 2018

I used react-component-component to create local state on the page and update it.

Example

Code

So in your case it would be :


import Component from "react-component-component";
<Playground>
  <Component initialState={{ isToggled: false }}>
    {component => {
      return (
        <UIToggle
          isToggled={component.state.isToggled}
          onToggle={() => {
            component.setState(state => ({ isToggled: !state.isToggled }));
          }}
        />
      );
    }}
  </Component>
</Playground>;

Hope that helps !

1reaction
dotlouiscommented, Oct 11, 2018

This would help being documented. I searched for quite some time before getting here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

dynamic update component in playground? #223 - GitHub
Is it possible to dynamic update a component in Playground? Description I would like to have a working example in the Playground.
Read more >
Playground Dynamic Component - StackBlitz
Starter project for Angular apps that exports to the Angular CLI.
Read more >
Dynamic component creation in Lightning Web Components
The usual Web Components can be dynamically created through standard DOM APIs like document.createElement('c-my-cmp') or element.appendChild( ...
Read more >
11 React UI Component Playgrounds for 2019 - Bits and Pieces
Top component playgrounds to render, view and develop React UI components online. Hot reload, simple configurations and much more.
Read more >
Surface.Components.Dynamic.Component — surface v0.9.1
A built-in component that allows users to inject dynamic components into a Surface template.
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