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.

šŸ‘‹ First off, thank you very much for making this! Iā€™ve used component-playground for a while, and have found this to be a really easy transition so far.

The one finicky thing Iā€™m running into is ā€œhowā€ Iā€™m writing my components that I pass into the code param.

My .babelrc looks like this:

{
  "presets": [
    ["env", {
      "targets": {
        "browsers": ["last 2 versions"]
      }
    }],
    "stage-0",
    "react"
  ],
  "plugins": [
    "transform-strict-mode"
  ]
}

Hereā€™s an example Iā€™m attempting to use:

const AlertExample = `
class Example extends React.Component {
  state = {
    toggleAlert: false,
  };

  handleToggleAlert = () => {
    this.setState({
      toggleAlert: !this.state.toggleAlert,
    });
  }

  render() {
    return (
      <Fragment>
        <Alert collapse={this.state.toggleAlert} type="primary" close>Test 1</Alert>
        <Button type="reset" onClick={this.handleToggleAlert} >Toggle Alert</Button>
      </Fragment>
    );
  }
}
`.trim();

so Iā€™m using a few niceties when I write my own components. It looks like when passing that same type of code into <LiveProvider /> it doesnā€™t appear to be compiling, and blows up because of a syntax issue. Is there a way for react-live to take advantage of my babel config?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9

github_iconTop GitHub Comments

3reactions
zslabscommented, Apr 6, 2018

I ended up using:

<LiveProvider
  scope={props.scope}
  code={props.code}
  mountStylesheet={false}
  transformCode={input => transform(input, { presets: ['stage-0', 'react'] }).code}
>
  <LiveEditor />
  <LivePreview />
  <LiveError />
</LiveProvider>
1reaction
kittencommented, Mar 13, 2018

No, currently react-live neither uses babel-standalone nor does it allow extensive customisation of the transpilation that it performs. It currently just uses BublƩ, so whatever BublƩ is able to transpile, react-live will also accept.

Iā€™ve read in another issue (not sure if GH or somewhere else?) that someone is currently simply using the transformCode prop using babel-standalone. Maybe you can give that a try?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configure Babel
Babel can be configured! Many other tools have similar configs: ESLint ( .eslintrc ), Prettier ( .prettierrc ). All Babel API options are...
Read more >
Advanced Features: Customizing Babel Config - Next.js
Customizing Babel Config ... Next.js includes the next/babel preset to your app, which includes everything needed to compile React applications and server-sideĀ ...
Read more >
When to use babel.config.js and .babelrc - Stack Overflow
From the docs https://babeljs.io/docs/en/config-files#project-wide-configuration. Babel has two parallel config file formats which can beĀ ...
Read more >
An example of the new babel.config.js. - gists Ā· GitHub
babel.config.js with useful plugins. */. module.exports = function(api) {. api.cache(true);. api.assertVersion("^7.4.5");. const presets = [.
Read more >
How to Configure Babel For Your Monorepo
In this post join me as I add Babel configuration to a monorepo, making sure that it can sustain different configurations packages need...
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