{"id":17800101,"url":"https://github.com/justinvdm/unroll-element","last_synced_at":"2026-01-21T16:33:42.884Z","repository":{"id":33494739,"uuid":"157085721","full_name":"justinvdm/unroll-element","owner":"justinvdm","description":"unroll react elements using your own host element resolver","archived":false,"fork":false,"pushed_at":"2022-04-24T19:04:33.000Z","size":1937,"stargazers_count":0,"open_issues_count":8,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-03-23T12:50:39.862Z","etag":null,"topics":["element","jsx","react","resolve","unroll"],"latest_commit_sha":null,"homepage":null,"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/justinvdm.png","metadata":{"files":{"readme":"readme.md","changelog":"CHANGELOG.md","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-11-11T14:08:23.000Z","updated_at":"2020-09-01T02:27:46.000Z","dependencies_parsed_at":"2022-08-07T21:17:13.008Z","dependency_job_id":null,"html_url":"https://github.com/justinvdm/unroll-element","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinvdm%2Funroll-element","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinvdm%2Funroll-element/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinvdm%2Funroll-element/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justinvdm%2Funroll-element/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/justinvdm","download_url":"https://codeload.github.com/justinvdm/unroll-element/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247666016,"owners_count":20975788,"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":["element","jsx","react","resolve","unroll"],"created_at":"2024-10-27T12:15:03.938Z","updated_at":"2026-01-21T16:33:37.861Z","avatar_url":"https://github.com/justinvdm.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# unroll-element\n\n[![Build Status](https://travis-ci.org/justinvdm/unroll-element.svg?branch=master)](https://travis-ci.org/justinvdm/unroll-element)\n\nSimple utility for unrolling react elements with function-based components as their types. Useful when using jsx for static, non-react use cases (e.g. a pdf renderer).\n\n```js\nimport unrollElement from 'unroll-element'\n\nconst Report = ({ title }) =\u003e (\n  \u003cdocument\u003e\n    \u003ctext\u003e{title}\u003c/text\u003e\n  \u003c/document\u003e\n);\n\nunrollElement(\u003cReport title='A report!' /\u003e, (el, children) =\u003e\n [el.type, children]);\n// =\u003e ['document', ['text', 'A report!']]\n```\n\n## api\n\n### `unrollElement(el, resolverFn[, context])`\nTakes in a react element `el` and returns a tree of objects, where each object is a result returned by `resolverFn`.\n\n`resolverFn` has the form `(el, children, i, context)`, where `el` is a [host element](https://reactjs.org/docs/implementation-notes.html#mounting-host-elements) to resolve, `children` is its resolved children and `i` is the index of element `el` in its parent's `children` after flattening arrays and fragments, or `null` if there is only a single child in the parent, or if `el` is the root element.\n\nFor elements with a single child, the resolved child is passed as `children`. For elements with multiple children, an array of resolved children is passed as `children`. For leaf elements, `children` is the value the of the element's `'children'` prop, or `undefined` if no such prop exists. Non-element child values are not passed to `resolveFn`, and are instead used as is. Fragment and array child values are flattened before being passed as `children`.\n\nAn optional `context` can be given to `unrollElement`, which is then passed as an argument for each call to `resolverFn`.\n\n## install\n\nYou can use this library as the npm package `unroll-element`:\n\n```\nnpm i unroll-element\n# or\nyarn add unroll-element\n```\n\nIt can be used in both es-module-aware and commonjs bundlers/environments.\n\n```js\n// es module\nimport unrollElement from 'unroll-element'\n\n// commonjs\nconst unrollElement = require('unroll-element')\n```\n\nIt can also be used a `\u003cscript\u003e` if necessary:\n\n```html\n\u003cscript crossorigin src=\"https://unpkg.com/unroll-element/dist/umd/unroll-element.js\"\u003e\u003c/script\u003e\n\n\u003cscript\u003e\nunrollElement(...)\n\u003c/script\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustinvdm%2Funroll-element","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjustinvdm%2Funroll-element","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustinvdm%2Funroll-element/lists"}