{"id":29118856,"url":"https://github.com/atticoos/react-predicate","last_synced_at":"2026-03-09T10:31:37.392Z","repository":{"id":57342722,"uuid":"82417079","full_name":"atticoos/react-predicate","owner":"atticoos","description":"A control-flow library for React","archived":false,"fork":false,"pushed_at":"2017-02-19T20:26:49.000Z","size":10,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-19T20:07:42.172Z","etag":null,"topics":["javascript","react","react-native","reactjs"],"latest_commit_sha":null,"homepage":null,"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/atticoos.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":"2017-02-18T21:25:30.000Z","updated_at":"2019-05-10T12:47:57.000Z","dependencies_parsed_at":"2022-09-16T02:50:35.865Z","dependency_job_id":null,"html_url":"https://github.com/atticoos/react-predicate","commit_stats":null,"previous_names":["ajwhite/react-predicate"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/atticoos/react-predicate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atticoos%2Freact-predicate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atticoos%2Freact-predicate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atticoos%2Freact-predicate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atticoos%2Freact-predicate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atticoos","download_url":"https://codeload.github.com/atticoos/react-predicate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atticoos%2Freact-predicate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30291807,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T02:57:19.223Z","status":"ssl_error","status_checked_at":"2026-03-09T02:56:26.373Z","response_time":61,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["javascript","react","react-native","reactjs"],"created_at":"2025-06-29T13:05:29.501Z","updated_at":"2026-03-09T10:31:37.363Z","avatar_url":"https://github.com/atticoos.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-predicate\n\nA control-flow library for React.\n\nThis library offers two categories of predicate components: `Condition` and `Switch`.\n\n```js\n\u003cCondition\u003e\n  \u003cIf condition={value === 'foo'}\u003e\n    \u003cspan\u003eFoo\u003c/span\u003e\n  \u003c/If\u003e\n  \u003cElseIf condition={value === 'bar'}\u003e\n    \u003cspan\u003eBar\u003c/span\u003e\n  \u003c/ElseIf\u003e\n  \u003cElse\u003e\n    \u003cspan\u003eThe value was neither foo nor bar\u003c/span\u003e\n  \u003c/Else\u003e\n\u003c/Condition\u003e\n```\n```js\n\u003cSwitch on={value}\u003e\n  \u003cCase when=\"foo\" break\u003e\n    \u003cspan\u003eFoo\u003c/span\u003e\n  \u003c/Case\u003e\n  \u003cCase when=\"bar\" break\u003e\n    \u003cspan\u003eBar\u003c/span\u003e\n  \u003c/Case\u003e\n  \u003cDefault\u003e\n    \u003cspan\u003eThe value was neither foo nor bar\u003c/span\u003e\n  \u003c/Default\u003e\n\u003c/Switch\u003e\n```\n\n### Condition\n\n`Condition` wraps a set of `If`, `ElseIf`, and `Else` components. Each component has a `condition` property, where the first to evaluate as `true` becomes rendered. If none evaluate to `true`, then `Else` becomes rendered if it exists. Alternatively, `If` can be used on its own when there is no alternative behavior.\n\n#### Condition Example\n\n```js\nclass Counter extends React.Component {\n  state = {count: 0};\n\n  increment() {\n    this.setState({count: this.state.count + 1});\n  }\n\n  decrement() {\n    this.setState({count: this.state.count - 1});\n  }\n\n  render() {\n    return (\n      \u003cdiv\u003e\n        \u003cbutton onClick={() =\u003e this.decrement()}\u003eDecrement\u003c/button\u003e\n        \u003cspan\u003e{this.state.count}\u003c/span\u003e\n        \u003cbutton onClick={() =\u003e this.increment()}\u003eIncrement\u003c/button\u003e\n        \u003cOddOrEven count={this.state.count}\u003c/OddOrEven\u003e\n      \u003c/div\u003e\n    );\n  }\n}\n\nfunction OddOrEven ({count}) {\n  return (\n    \u003cCondition\u003e\n      \u003cIf condition={count % 2 === 0}\u003e\n        \u003cspan\u003eThe number is even\u003c/span\u003e\n      \u003c/If\u003e\n      \u003cElse\u003e\n        \u003cspan\u003eThe number is odd\u003c/span\u003e\n      \u003c/Else\u003e\n    \u003c/Condition\u003e\n  );\n}\n```\n\n#### If example\n\nIn this example we use `If` without a parent `Condition`. When `If` is not wrapped by a `Condition`, the statements are not aware of each other. Unlike `Condition`, if one evaluates to `true`, the other remains unaffected.\n\n```js\nclass Counter extends React.Component {\n  state = {count: 0};\n\n  increment() {\n    this.setState({count: this.state.count + 1});\n  }\n\n  decrement() {\n    this.setState({count: this.state.count - 1});\n  }\n\n  render() {\n    return (\n      \u003cdiv\u003e\n        \u003cbutton onClick={() =\u003e this.decrement()}\u003eDecrement\u003c/button\u003e\n        \u003cspan\u003e{this.state.count}\u003c/span\u003e\n        \u003cbutton onClick={() =\u003e this.increment()}\u003eIncrement\u003c/button\u003e\n        \u003cIf condition={this.state.count % 2 === 0}\u003e\n          \u003cspan\u003eThe number is even\u003c/span\u003e\n        \u003c/If\u003e\n        \u003cIf condition={this.state.count % 2 === 0}\u003e\n          \u003cspan\u003eThe number is still even\u003c/span\u003e\n        \u003c/If\u003e\n        \u003cIf condition={this.state.count % 2 !== 0}\u003e\n          \u003cspan\u003eThe number is odd\u003c/span\u003e\n        \u003c/If\u003e\n      \u003c/div\u003e\n    );\n  }\n}\n```\n\n### Lazy evaluation\n\nIn certain scenarios it's important that you conditional content is not rendered unless the predicate passes.\nFor any of the predicate components, a function can be provided as the child.\n```js\n\u003cIf condition={1 + 1 === 2}\u003e\n  {() =\u003e \u003cConditionalComponent /\u003e}\n\u003c/If\u003e\n```\n\n```js\nclass LazyEvaluation extends React.Component {\n  state = {person: null};\n\n  createModel() {\n    this.setState({\n      person: {name: 'Hello World'}\n    });\n  }\n\n  render() {\n    return (\n      \u003cdiv\u003e\n        \u003cbutton onClick={() =\u003e this.createModel()}\u003eCreate\u003c/button\u003e\n\n        \u003cCondition\u003e\n          \u003cIf condition={!!this.state.person}\u003e\n            {() =\u003e \u003cPerson person={this.state.person} /\u003e}\n          \u003c/If\u003e\n          \u003cElse\u003e\n            \u003cspan\u003eA person does not yet exist\u003c/span\u003e\n          \u003c/Else\u003e\n        \u003c/Condition\u003e\n      \u003c/div\u003e\n    );\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatticoos%2Freact-predicate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatticoos%2Freact-predicate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatticoos%2Freact-predicate/lists"}