https://github.com/donavon/render-fragment
https://github.com/donavon/render-fragment
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/donavon/render-fragment
- Owner: donavon
- License: mit
- Created: 2017-11-30T15:01:19.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-01T02:39:07.000Z (almost 8 years ago)
- Last Synced: 2025-05-20T08:43:22.332Z (5 months ago)
- Language: JavaScript
- Size: 32.2 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# render-fragment
[](https://travis-ci.org/donavon/render-fragment)
[](https://www.npmjs.com/package/render-fragment)
[](https://coveralls.io/github/donavon/render-fragment?branch=master)A convenient way to return a JSX fragment without the wrapping `div`
element and not worry about the version of React.## Install
```bash
$ npm i --save render-fragment
```With the introduction of React 16.2, you can now return a fragment
(i.e. multiple elements that are not under a single element).
In previous versions, you were required to return either a
single element (in version 15.x)
or an array (in version 16.0 and 16.1).```js
import Fragment from 'render-fragment';const App = () => (
A
B
);
```If you are running React 15.x, it will render a wrapping `
`.
For React 16.0 and 16.1, it will render an array.
For React 16.2 and above, it will render a ``.This way you can use the same markup regardless of the version
of React that you are using.
This is really useful for component designers that have React
installed as a peerDependency.See live example on [CodeSandbox](https://codesandbox.io/s/xp55rmrz8w).