{"id":21450924,"url":"https://github.com/soontao/react-visible-control","last_synced_at":"2026-04-17T00:35:15.759Z","repository":{"id":41242474,"uuid":"120467503","full_name":"Soontao/react-visible-control","owner":"Soontao","description":"Control the rendering or non-rendering of components in simple way","archived":false,"fork":false,"pushed_at":"2023-12-15T05:17:12.000Z","size":51,"stargazers_count":1,"open_issues_count":3,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-25T20:40:30.594Z","etag":null,"topics":["context","react","react-component","react-native"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Soontao.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-06T14:13:05.000Z","updated_at":"2018-02-27T07:48:18.000Z","dependencies_parsed_at":"2023-01-21T09:18:17.130Z","dependency_job_id":null,"html_url":"https://github.com/Soontao/react-visible-control","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/Soontao%2Freact-visible-control","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soontao%2Freact-visible-control/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soontao%2Freact-visible-control/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soontao%2Freact-visible-control/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Soontao","download_url":"https://codeload.github.com/Soontao/react-visible-control/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243963633,"owners_count":20375653,"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":["context","react","react-component","react-native"],"created_at":"2024-11-23T04:17:09.695Z","updated_at":"2026-04-17T00:35:15.704Z","avatar_url":"https://github.com/Soontao.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# React Visible Control\n\n[![CircleCI](https://circleci.com/gh/Soontao/react-visible-control.svg?style=shield)](https://circleci.com/gh/Soontao/react-visible-control) [![codecov](https://codecov.io/gh/Soontao/react-visible-control/branch/master/graph/badge.svg)](https://codecov.io/gh/Soontao/react-visible-control) [![npm version](https://badge.fury.io/js/react-visible-control.svg)](https://badge.fury.io/js/react-visible-control)\n\nControl the rendering or non-rendering of components in simple way.\n\nWorks for React \u0026 React Native.\n\nWARNING!!!, please make sure you know what you are doing !\n\nthis lib use [React Context API](https://reactjs.org/docs/context.html), please make sure the `shouldComponentUpdate` method works correct in your project\n\n## install\n\n```bash\nnpm i -S react-visible-control\n```\n\n## sample application\n\n[Here is a sample application based on react-visible-control](https://github.com/Soontao/react-visible-control-sample)\n\nBasic usage as following\n\n```jsx\nimport React, { Component } from 'react';\nimport { Failback, VisibleContext, VisibleControl } from 'react-visible-control';\n\n\nconst visibleData = { \"home\": true, \"page1\": true, \"page2\": false }\n\nexport default class Test extends Component {\n  render() {\n    return (\n      \u003cVisibleContext data={visibleData}\u003e\n        \u003cdiv\u003e\n          \u003cVisibleControl visibleKey={\"home\"}\u003e\n            \u003cp\u003ehome\u003c/p\u003e\n          \u003c/VisibleControl\u003e\n          \u003cVisibleControl visibleKey={\"page1\"}\u003e\n            \u003cp\u003epage1\u003c/p\u003e\n          \u003c/VisibleControl\u003e\n          \u003cVisibleControl visibleKey={\"page2\"}\u003e\n            \u003cp\u003epage2\u003c/p\u003e\n            \u003cFailback\u003e\u003cp\u003eyou cant access page2, but you could show a failback thing here\u003c/p\u003e\u003c/Failback\u003e\n          \u003c/VisibleControl\u003e\n          \u003cVisibleControl visibleKey={\"page3\"}\u003e\n            \u003cp\u003epage3\u003c/p\u003e\n          \u003c/VisibleControl\u003e\n        \u003c/div\u003e\n      \u003c/VisibleContext\u003e\n    );\n  }\n}\n```\n\nRender Result: \n\n```html\n\u003cdiv\u003e\n  \u003cp\u003e\n    home\n  \u003c/p\u003e\n  \u003cp\u003e\n    page1\n  \u003c/p\u003e\n  \u003cp\u003e\n    you cant access page2, but you could show a failback thing here\n  \u003c/p\u003e\n\u003c/div\u003e\n```\n\n## custom usage\n\nin this demo, without permission, react will not render child component\n\n```javascript\n\n// mock user data\nconst users = [\n  {\n    \"name\": \"Theo Sun\",\n    \"permissions\": [\n      \"user_read\",\n      \"user_write\",\n      \"user_update\",\n      \"user_delete\"\n    ],\n    \"role\": \"user_manager\"\n  },\n  {\n    \"name\": \"Cherry Xu\",\n    \"permissions\": [\"user_read\"],\n    \"role\": \"user_viewer\"\n  }\n\n];\n\n// custome Control\nconst userHavePermission = per =\u003e data =\u003e data.permissions \u0026\u0026 data.permissions.indexOf(per) \u003e= 0\n\nexport const UserReadPermission   = createVisibleControl(userHavePermission(\"user_read\"));\nexport const UserWritePermission  = createVisibleControl(userHavePermission(\"user_write\"));\nexport const UserDeletePermission = createVisibleControl(userHavePermission(\"user_delete\"));\nexport const UserUpdatePermission = createVisibleControl(userHavePermission(\"user_update\"));\n\n// app view\nclass App extends Component {\n\n  constructor(props) {\n    super(props);\n    this.state = {\n      \"counter\": 0,\n      \"visibleData\": {}\n    };\n  }\n\n  render() {\n    return (\n      \u003cVisibleContext data={this.state.visibleData}\u003e\n        \u003cbutton onClick={() =\u003e {\n          this.setState({ \"visibleData\": users[this.state.counter % users.length] });\n          this.setState({ \"counter\": this.state.counter + 1 });\n        }} \u003e\n          change user\u003c/button\u003e\n        \u003cdiv className=\"App\"\u003e\n          \u003cUserDeletePermission\u003e\u003cp\u003eYou have User Delete Permission\u003c/p\u003e\u003c/UserDeletePermission\u003e\n          \u003cUserWritePermission\u003e\u003cp\u003eYou have User Write Permission\u003c/p\u003e\u003c/UserWritePermission\u003e\n          \u003cUserReadPermission\u003e\u003cp\u003eYou have User Read Permission\u003c/p\u003e\u003c/UserReadPermission\u003e\n          \u003cUserUpdatePermission\u003e\u003cp\u003eYou have User Update Permission\u003c/p\u003e\u003c/UserUpdatePermission\u003e\n        \u003c/div\u003e\n      \u003c/VisibleContext\u003e\n    );\n  }\n}\n```\n\n## License \n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoontao%2Freact-visible-control","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoontao%2Freact-visible-control","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoontao%2Freact-visible-control/lists"}