{"id":19353609,"url":"https://github.com/benwiley4000/react-dot-fragment","last_synced_at":"2025-04-23T07:31:30.987Z","repository":{"id":52140070,"uuid":"125011207","full_name":"benwiley4000/react-dot-fragment","owner":"benwiley4000","description":"🦄 Use React 16's \u003cReact.Fragment\u003e in React 15","archived":false,"fork":false,"pushed_at":"2023-01-04T21:37:01.000Z","size":171,"stargazers_count":21,"open_issues_count":5,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T10:12:00.713Z","etag":null,"topics":["dom","fragment","hacks","polyfill","ponyfill","react"],"latest_commit_sha":null,"homepage":"https://benwiley4000.github.io/react-dot-fragment/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/benwiley4000.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-13T07:38:03.000Z","updated_at":"2023-07-13T06:36:59.000Z","dependencies_parsed_at":"2023-02-02T20:46:13.486Z","dependency_job_id":null,"html_url":"https://github.com/benwiley4000/react-dot-fragment","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benwiley4000%2Freact-dot-fragment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benwiley4000%2Freact-dot-fragment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benwiley4000%2Freact-dot-fragment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benwiley4000%2Freact-dot-fragment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benwiley4000","download_url":"https://codeload.github.com/benwiley4000/react-dot-fragment/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250391281,"owners_count":21422870,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dom","fragment","hacks","polyfill","ponyfill","react"],"created_at":"2024-11-10T04:43:28.755Z","updated_at":"2025-04-23T07:31:30.600Z","avatar_url":"https://github.com/benwiley4000.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-dot-fragment\n\nThis is a very simple ponyfill for React 16's [`\u003cReact.Fragment\u003e`](https://reactjs.org/docs/fragments.html) (a.k.a. `\u003c\u003e`) component which allows a component to return a set of children without a wrapper DOM element.\n\n```bash\nnpm install react-dot-fragment\n```\n\n## example\n\n([see a working example here](https://benwiley4000.github.io/react-dot-fragment/))\n\n```html\n\u003chtml\u003e\n\u003cbody\u003e\n  \u003cul\u003e\u003c/ul\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n```jsx\nimport React from 'react';\nimport ReactDOM from 'react-dom';\nimport Fragment from 'react-dot-fragment';\n\nReactDOM.render(\n  \u003cFragment\u003e\n    \u003cli\u003ea\u003c/li\u003e\n    \u003cli\u003eb\u003c/li\u003e\n    \u003cli\u003ec\u003c/li\u003e\n  \u003c/Fragment\u003e,\n  document.querySelector('ul')\n);\n```\n\nThe DOM becomes:\n```html\n\u003chtml\u003e\n\u003cbody\u003e\n  \u003cul\u003e\n    \u003cli\u003ea\u003c/li\u003e\n    \u003cli\u003eb\u003c/li\u003e\n    \u003cli\u003ec\u003c/li\u003e\n  \u003c/ul\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n## how does it work?\n\n1. In the render method of our `Fragment` component, wrap the the `children` prop with a `\u003cdiv\u003e`\n2. After the component mounts, attach the child DOM nodes to our `\u003cdiv\u003e`'s parent DOM node\n3. Hide the `\u003cdiv\u003e` from the DOM so it doesn't affect any layout\n3. On update:\n\n    a. Move the elevated child nodes back inside the `\u003cdiv\u003e`\n\n    b. Let React re-render\n\n    c. Move the new child nodes back up to the `\u003cdiv\u003e`'s parent node\n\n## rationale\n\nYou might want to use this for one of a couple of *good* reasons:\n* You have some code that needs to be tested in React 15, but it relies on `React.Fragment`.\n* You maintain a React library which supports React 16 features, but you want backward compatibility.\n\nGenerally, if you want to use `React.Fragment`, it's probably best to just upgrade to React 16.\n\n## compatibility\n\nThis module works with React 15 or later. It works in Node or in the browser.\n\nSince the current solution relies on the DOM, this module is *not* compatible with React Native or other React platforms without access to the DOM API. If you would like to help us fix that, [please open a PR](https://github.com/benwiley4000/react-dot-fragment/issues/3)!\n\n## contributing\n\nPlease feel free to open a pull request with test cases, bug fixes, or the like.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenwiley4000%2Freact-dot-fragment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenwiley4000%2Freact-dot-fragment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenwiley4000%2Freact-dot-fragment/lists"}