{"id":22143433,"url":"https://github.com/hc-oss/control-statements","last_synced_at":"2026-05-02T20:36:18.339Z","repository":{"id":57206628,"uuid":"172887827","full_name":"hc-oss/control-statements","owner":"hc-oss","description":"Clean way to write loops and conditions in JSX ✨","archived":false,"fork":false,"pushed_at":"2019-09-23T07:11:10.000Z","size":108,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-12T06:06:20.496Z","etag":null,"topics":["conditions","loops","ng-if","reactjs"],"latest_commit_sha":null,"homepage":"","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/hc-oss.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":"2019-02-27T09:46:43.000Z","updated_at":"2022-09-26T10:54:56.000Z","dependencies_parsed_at":"2022-09-08T14:22:20.685Z","dependency_job_id":null,"html_url":"https://github.com/hc-oss/control-statements","commit_stats":null,"previous_names":["harshzalavadiya/control-statements"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hc-oss/control-statements","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hc-oss%2Fcontrol-statements","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hc-oss%2Fcontrol-statements/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hc-oss%2Fcontrol-statements/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hc-oss%2Fcontrol-statements/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hc-oss","download_url":"https://codeload.github.com/hc-oss/control-statements/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hc-oss%2Fcontrol-statements/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32549383,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-02T19:18:06.202Z","status":"ssl_error","status_checked_at":"2026-05-02T19:16:21.335Z","response_time":132,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["conditions","loops","ng-if","reactjs"],"created_at":"2024-12-01T22:10:40.061Z","updated_at":"2026-05-02T20:36:13.331Z","avatar_url":"https://github.com/hc-oss.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm version](https://img.shields.io/npm/v/control-statements.svg?style=flat-square)](https://www.npmjs.com/package/control-statements)\n[![Build Status](https://travis-ci.org/harshzalavadiya/control-statements.svg?branch=master)](https://travis-ci.org/harshzalavadiya/control-statements)\n\nThere's no built-in looping and conditional syntax in React. This library adds the syntactic sugar to write looping and conditionals as component.\n\nFork of [react control statements](https://www.npmjs.com/package/react-control-statements) but with `\u003cReact.Fragment/\u003e` implementation\n\n## Free Advise\n\nIf you are coming from non-jsx background you might think this package is a good start but in reality 🤫 *this package is not needed at all.*\n\nbecause, it's easy to replicate this scenarios with pure ES6+, I'm putting some examples that might help you for getting started.\n\n### Pure React Conditional Statements\n[![Edit SimpleConditionalStatements](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/peaceful-bhaskara-q35fy?fontsize=14)\n```jsx\nimport React from \"react\";\n\nexport default function PureReactExamples() {\n  const foo = true;\n  const fruits = [\"🍇 Grapes\", \"🍈 Melon\", \"🍌 Banana\"];\n  return (\n    \u003c\u003e\n      \u003ch1\u003eSimple If without Else\u003c/h1\u003e\n      {foo \u0026\u0026 \u003cp\u003eYay, Foo is true\u003c/p\u003e}\n\n      \u003ch1\u003eSimple If with Else\u003c/h1\u003e\n      {foo ? \u003cp\u003eYay, Foo is true\u003c/p\u003e : \u003cp\u003eWhoa, Foo is false\u003c/p\u003e}\n\n      \u003ch1\u003eLoop Example\u003c/h1\u003e\n      {fruits.map((fruitName, index) =\u003e (\n        \u003cp key={index}\u003e{fruitName}\u003c/p\u003e\n      ))}\n    \u003c/\u003e\n  );\n}\n```\n\n---\n\n## Install\n\n```\nnpm install --save control-statements\n```\n\n## Usage\n\n### If\n\nThe body of the if statement only gets evaluated if condition is true.\n\n```jsx\nimport React, { Component } from \"react\";\nimport { If } from \"control-statements\";\n\nclass YourComponent extends Component {\n  render() {\n    \u003cIf condition={test}\u003e\n      \u003cspan\u003eTruth\u003c/span\u003e\n    \u003c/If\u003e;\n  }\n}\n```\n\n### Choose\n\nThis is an alternative syntax for more complex conditional statements.\n\n```jsx\nimport React, { Component } from \"react\";\nimport { Choose, When, Otherwise } from \"control-statements\";\n\nclass YourComponent extends Component {\n  render() {\n    return (\n      \u003cdiv\u003e\n        \u003cChoose\u003e\n          \u003cWhen condition={test1}\u003e\n            \u003cspan\u003eIfBlock\u003c/span\u003e\n          \u003c/When\u003e\n          \u003cWhen condition={test2}\u003e\n            \u003cspan\u003eElseIfBlock\u003c/span\u003e\n            \u003cspan\u003eAnother ElseIfBlock\u003c/span\u003e\n            \u003cspan\u003e...\u003c/span\u003e\n          \u003c/When\u003e\n          \u003cOtherwise\u003e\n            \u003cspan\u003eElseBlock\u003c/span\u003e\n          \u003c/Otherwise\u003e\n        \u003c/Choose\u003e\n      \u003c/div\u003e\n    );\n  }\n}\n```\n\n### For\n\nFor syntax.\n\n```jsx\nimport React, { Component } from \"react\";\nimport { For } from \"control-statements\";\n\nclass YourComponent extends Component {\n  render() {\n    return (\n      \u003cdiv\u003e\n        \u003cFor each=\"$item\" of={this.props.items}\u003e\n          \u003cspan key=\"$item.id\"\u003e$item.title\u003c/span\u003e\n        \u003c/For\u003e\n      \u003c/div\u003e\n    );\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhc-oss%2Fcontrol-statements","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhc-oss%2Fcontrol-statements","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhc-oss%2Fcontrol-statements/lists"}