Use or similar tags in ReactJS using JSX

后端 未结 2 1582
Happy的楠姐
Happy的楠姐 2021-01-02 18:00

I am trying to use ReactJS with JSX to create a proof of concept for a styleguide.

I wanted to be able to display the raw html of how to call on components doing t

2条回答
  •  星月不相逢
    2021-01-02 18:19

    If you want that code as literal block, you'll need to use JSX-safe characters, so either JSX-escape everything, or use HTML entities where you can and then you still need to JSX-escape the curly brackets (because those are templating syntax in JSX) and newlines (yes, those newlines are not JSX-safe, either. Whitespace is collapsed during JSX transformation).

    And you probably want to use a

    , which is a block-level element for formatted text, rather than , which is inline:

      <VideoPlayer{'\n'}
        ref="videoplayer"{'\n'}
        preload={'{'}this.props.preload{'}\n'}
        classes={'{'}this.props.classes{'}\n'}
        videoID={'{'}this.props.videoID{'}\n'}
        controls="controls"{'\n'}
      />

    "That's so much work O_o", yeah it is. So usually you don't bother doing this yourself; if you use a bundler, you use a preprocessor (like block-loader if you're using webpack), or if you don't you often use a special react component that renders text verbatim.

提交回复
热议问题