{"id":17172206,"url":"https://github.com/lucasconstantino/react-path-tracker","last_synced_at":"2025-10-03T19:41:54.361Z","repository":{"id":57342310,"uuid":"126742871","full_name":"lucasconstantino/react-path-tracker","owner":"lucasconstantino","description":":paw_prints: Easily track traveled paths on highly dynamic or recursive React trees","archived":false,"fork":false,"pushed_at":"2019-04-16T16:55:08.000Z","size":142,"stargazers_count":12,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T07:03:50.024Z","etag":null,"topics":["path","react","recursion"],"latest_commit_sha":null,"homepage":"https://github.com/lucasconstantino/react-path-tracker","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/lucasconstantino.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-25T21:43:20.000Z","updated_at":"2018-04-01T20:17:30.000Z","dependencies_parsed_at":"2022-09-16T02:50:26.267Z","dependency_job_id":null,"html_url":"https://github.com/lucasconstantino/react-path-tracker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasconstantino%2Freact-path-tracker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasconstantino%2Freact-path-tracker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasconstantino%2Freact-path-tracker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasconstantino%2Freact-path-tracker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucasconstantino","download_url":"https://codeload.github.com/lucasconstantino/react-path-tracker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248741199,"owners_count":21154255,"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":["path","react","recursion"],"created_at":"2024-10-14T23:36:24.460Z","updated_at":"2025-10-03T19:41:54.256Z","avatar_url":"https://github.com/lucasconstantino.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# React Path Tracker\n\n:paw_prints: Easily track traveled paths on highly dynamic or recursive React trees.\n\n[![Build status](https://travis-ci.org/lucasconstantino/react-path-tracker.svg?branch=master)](https://travis-ci.org/lucasconstantino/react-path-tracker)\n\n## Installation\n\n```\nnpm install react-path-tracker\n```\n\n## Motivation\n\nI was once working on a layout builder for React which had some recursive needs; we had rows, which could have items, which could have rows of their own, and thus items of their own. Rendering was no big deal, but having the editing capability on this recursive tree was tricky. On each item, it was important to record what exactly was the path traveled to reach it, so that we could perform alterations such as dragging the item to a new location or resizing it. Thats why we created PathTracker, a lib with a render prop API pattern and no logic attached, so to make it easy to use regardless on what components are making the recursion happen.\n\n## How does it work\n\nThis project exposes a `PathTracker` component - responsible for registering the traveled path - and a `PathConsumer` component - responsible for accessing the registered path.\n\n## Usage\n\n### API\n\n#### PathTracker\n\nProp | Type | Default | Description\n---------|------|---------|------------\n`path` | Array | `[]` | Traveled path to register.\n`reset` | Boolean | `false` | Reset path from this point down.\n`children` | Element | `null` | React element.\n\n#### PathConsumer\n\nProp | Type | Default | Description\n---------|------|---------|------------\n`children` | Function | `void` | Function to render underlying elements ([render prop](https://reactjs.org/docs/render-props.html)).\n`children.args[0]` | Array | `[]` | The currently registered traveled path.\n\n### Example\n\nFor the following code:\n\n```js\nimport { PathTracker, PathConsumer } from 'react-path-tracker'\n\nconst list = [\n  { title: 'First', items: [{ title: 'First/First' }, { title: 'First/Second' }] },\n  { title: 'Second', items: [{ title: 'Second/First', items: [{ title: 'Second/First/First' }] }] }\n]\n\nconst List = ({ items = [] }) =\u003e (\n  \u003cul\u003e\n    items.map(({ title, items }, index) =\u003e (\n      \u003cli key={ title }\u003e\n        \u003cPathTracker path={ ['items', index] }\u003e\n          \u003cItem title={ title } items={ items } /\u003e\n        \u003c/PathTracker\u003e\n      \u003c/li\u003e\n    ))\n  \u003c/ul\u003e\n)\n\nconst Item = ({ title, items = [] }) =\u003e (\n  \u003cPathConsumer\u003e\n    { path =\u003e (\n      \u003cdiv\u003e\n        \u003ch3\u003e{ title }\u003c/h3\u003e\n        Path: \u003cpre\u003e{ JSON.stringify(path) }\u003c/pre\u003e\n        { items.length \u0026\u0026 \u003cList items={ items } /\u003e }\n      \u003c/div\u003e\n    ) }\n  \u003c/PathConsumer\u003e\n)\n\nrender(\u003cList items={ list } /\u003e)\n```\n\n...expect the following markup:\n\n```html\n\u003cul\u003e\n  \u003cli\u003e\n    \u003cdiv\u003e\n      \u003ch3\u003eFirst\u003c/h3\u003e\n      Path: \u003cpre\u003e[\"items\",0]\u003c/pre\u003e\n      \u003cul\u003e\n        \u003cli\u003e\n          \u003cdiv\u003e\n            \u003ch3\u003eFirst/First\u003c/h3\u003e\n            Path: \u003cpre\u003e[\"items\",0,\"items\",0]\u003c/pre\u003e\n          \u003c/div\u003e\n        \u003c/li\u003e\n        \u003cli\u003e\n          \u003cdiv\u003e\n            \u003ch3\u003eFirst/Second\u003c/h3\u003e\n            Path: \u003cpre\u003e[\"items\",0,\"items\",1]\u003c/pre\u003e\n          \u003c/div\u003e\n        \u003c/li\u003e\n      \u003c/ul\u003e\n    \u003c/div\u003e\n  \u003c/li\u003e\n    \u003cli\u003e\n      \u003cdiv\u003e\n        \u003ch3\u003eSecond\u003c/h3\u003e\n        Path: \u003cpre\u003e[\"items\",1]\u003c/pre\u003e\n        \u003cul\u003e\n          \u003cli\u003e\n            \u003cdiv\u003e\n              \u003ch3\u003eSecond/First\u003c/h3\u003e\n              Path: \u003cpre\u003e[\"items\",1,\"items\",0]\u003c/pre\u003e\n              \u003cul\u003e\n                \u003cli\u003e\n                  \u003cdiv\u003e\n                    \u003ch3\u003eSecond/First/First\u003c/h3\u003e\n                    Path: \u003cpre\u003e[\"items\",1,\"items\",0,\"items\",0]\u003c/pre\u003e\n                  \u003c/div\u003e\n                \u003c/li\u003e\n              \u003c/ul\u003e\n            \u003c/div\u003e\n          \u003c/li\u003e\n        \u003c/ul\u003e\n      \u003c/div\u003e\n    \u003c/li\u003e\n\u003c/ul\u003e\n```\n\n## License\n\nCopyright (c) 2018 Lucas Constantino Silva\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\nof the Software, and to permit persons to whom the Software is furnished to do\nso, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucasconstantino%2Freact-path-tracker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucasconstantino%2Freact-path-tracker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucasconstantino%2Freact-path-tracker/lists"}