{"id":18993435,"url":"https://github.com/mdibyo/react-typed-context","last_synced_at":"2025-07-04T23:37:48.206Z","repository":{"id":57346804,"uuid":"134229532","full_name":"mDibyo/react-typed-context","owner":"mDibyo","description":null,"archived":false,"fork":false,"pushed_at":"2018-05-25T11:19:17.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-03T10:18:42.447Z","etag":null,"topics":[],"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/mDibyo.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-05-21T06:46:15.000Z","updated_at":"2018-05-25T11:19:02.000Z","dependencies_parsed_at":"2022-08-25T19:10:25.219Z","dependency_job_id":null,"html_url":"https://github.com/mDibyo/react-typed-context","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mDibyo%2Freact-typed-context","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mDibyo%2Freact-typed-context/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mDibyo%2Freact-typed-context/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mDibyo%2Freact-typed-context/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mDibyo","download_url":"https://codeload.github.com/mDibyo/react-typed-context/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240008063,"owners_count":19733249,"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":[],"created_at":"2024-11-08T17:21:24.667Z","updated_at":"2025-02-21T11:41:06.386Z","avatar_url":"https://github.com/mDibyo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-typed-context\n\nRuntime type-checking for React Context Providers.\n\n### Install\n\n```\nnpm install --save react-typed-context\n```\n\n### Introduction\n\nThis package adds runtime type-checking of the value provided to React `Context.Provider`s by leveraging the `prop-types` package.\n\n```js\nimport createContextOfType from 'react-typed-context';\nimport * as PropTypes from 'prop-types';\nimport * as React from 'react';\n\nconst CounterContext = createContextOfType(PropTypes.number.isRequired);\n\nconst Example1 = () =\u003e (\n  \u003cCounterContext.Provider value=\"1\"\u003e // Warning: Failed prop type: Invalid prop `value` of type `string` supplied to `PropTyped(Provider)`, expected `number`.\n    ...\n  \u003c/CounterContext.Provider\u003e\n);\n```\n\nIt takes an optional default value for the context.\n```js\nconst CounterContext = createContextOfType(PropTypes.number.isRequired, 0);\n\nconst Example2 = () =\u003e (\n  \u003cCounterContext.Provider\u003e\n    ...\n    \u003cCounterContext.Consumer\u003e{value =\u003e value}\u003c/CounterContext.Consumer\u003e // 0\n  \u003c/CounterContext.Provider\u003e\n);\n```\n\nThanks to the expressiveness of `prop-types`, arbitrarily complex values are supported.\n```js\nconst ReadWriteThemeContext = createContextOfType(\n  PropTypes.shape({\n    theme: PropTypes.string,\n    setTheme: PropTypes.func.isRequired,\n  },\n  { theme: 'dark' },\n);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdibyo%2Freact-typed-context","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmdibyo%2Freact-typed-context","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdibyo%2Freact-typed-context/lists"}