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.

Is it possible to render react class inside the `Playground` component?

See original GitHub issue

Question

First thank you for this awesome project 🚀

Description I was wondering, can we render react class inside the Playground component? For example like material ui is doing here https://material-ui.com/demos/dialogs/#simple-dialogs (you need to click on the “Show the source” button). Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
danielbayerleincommented, Jan 8, 2019

@pedronauck Looks like it’s no longer possible to render a class directly inside the playground with docz v0.13.7.

Code

<Playground>
  {class Example extends React.Component {
    constructor (props) {
      super(props)

      this.state = { showModal: false }
    }

    handleShowModal () {
      this.setState({ showModal: true })
    }

    handleCloseModal () {
      this.setState({ showModal: false })
    }

    render () {
      return (
        <React.Fragment>
          {this.state.showModal && <p>Lorem ipsum dolor sit amet</p>}
          <button onClick={() => this.handleCloseModal()}>Close Modal</button>
          <button onClick={() => this.handleShowModal()}>Show Modal</button>
        </React.Fragment>
      )
    }
  }}
</Playground>

Error

SyntaxError: Unexpected token (3:11)
1 : (<React.Fragment>
2 : class TestMyCode extends React.Component {
3 :   render() {
               ^
7reactions
three60fivecommented, Sep 13, 2018

I think this should have an example in the docz.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Lifecycle Methods Render And ComponentDidMount
If we are talking about lifecycle methods in React.js then render() is the most used method. If React component has to display any...
Read more >
Components and Props - React
Rendering a Component · We call root.render() with the <Welcome name="Sara" /> element. · React calls the Welcome component with {name: 'Sara'} as...
Read more >
Unable to render class method in the App component ( No error)
Your class method is running and returning a value in the first example, but nothing in your code is doing anything with the...
Read more >
Class Components - React TypeScript Cheatsheets
Within TypeScript, React.Component is a generic type (aka React.Component), so you want to provide it with (optional) prop and state type parameters:
Read more >
11 React UI Component Playgrounds for 2019 - Bits and Pieces
labs, component-playground is a component for rendering React components with editable source and live preview. It's built for fast and easy ...
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