Socket
Socket
Sign inDemoInstall

jsx-xray

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsx-xray

a react component to print out the jsx passed into it


Version published
Maintainers
1
Created
Source

jsx-xray

JSX Xray for React is a component that will render its children but will also reverse engineer their jsx, and print it along side in a popover box. This is handy for storybook demos where you want to have a working example, but also wish to provide sample jsx without having to hard code it. As a bonus, it also uses prism to highlight syntax and since it's computing the jsx, as you interact with your storybook demos, the jsx always matches what's rendered on screen.

Note that in order for the component names to be displayed correctly, you MUST have displayName set for the components which you pass into XRay.

#Github https://github.com/oshoghi/jsx

Usage

Anything wrapped in the component will get rendered alongside its associated jsx.

import React, { Component } from "react";
import { RockerButton } from "ui-lib"
import Jsx from "jsx-xray";

class Story extends Component {
    static state = { index: 0 };

    _handleRockerButtonClick = (index) => {
        this.setState({ index });
    };

    render () {
        return (
            <Jsx>
                <RockerButton 
                    labels={["button 1","button 2","another button"]}
                    selected={this.state.index}
                    className="autowidth"
                    onClick={this._handleRockerButtonClick} />
            </Jsx>
        )
    }
}

#Options JSX XRay comes with some reasonable defaults but you can override these by passing it the appropriate props:

substituteThreshold

The default value is 40 chars. This prop controls the length at which point XRay will swap out prop values and substitute them with variables. Eg:

<Jsx substituteThreshold={15}>
    <RockerButton 
        labels={["button 1","button 2","another button"]}
        selected={this.state.index}
        className="autowidth"
        onClick={this._handleRockerButtonClick} />
</Jsx>

This will cause the outputted jsx to look like this:

const labels = ([
    "button 1",
    "button 2",
    "another button"
]);

<RockerButton
    labels={labels}
    selected={-1}
    className="autowidth"
    onClick={function () {...}} />

oneLineThreshold

The default value for this prop is 64 chars. This prop controls at what length XRay will break a jsx line into multiple lines.

Keywords

FAQs

Package last updated on 10 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc