{"id":13572594,"url":"https://github.com/Asana/typed-react","last_synced_at":"2025-04-04T10:30:59.227Z","repository":{"id":21126776,"uuid":"24427655","full_name":"Asana/typed-react","owner":"Asana","description":"A binding layer between React and TypeScript","archived":true,"fork":false,"pushed_at":"2023-04-07T08:31:36.000Z","size":132,"stargazers_count":372,"open_issues_count":4,"forks_count":19,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-03-11T07:21:30.397Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/Asana.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-09-24T18:37:42.000Z","updated_at":"2024-12-18T01:48:11.000Z","dependencies_parsed_at":"2024-06-18T20:10:45.294Z","dependency_job_id":null,"html_url":"https://github.com/Asana/typed-react","commit_stats":{"total_commits":159,"total_committers":12,"mean_commits":13.25,"dds":0.2955974842767296,"last_synced_commit":"eda79378d348ff0a51ea8418a3aa7927cfd1f659"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Asana%2Ftyped-react","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Asana%2Ftyped-react/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Asana%2Ftyped-react/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Asana%2Ftyped-react/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Asana","download_url":"https://codeload.github.com/Asana/typed-react/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247160309,"owners_count":20893807,"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-08-01T14:01:27.851Z","updated_at":"2025-04-04T10:30:58.912Z","avatar_url":"https://github.com/Asana.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Typed React \n\n[![NPM Version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage][coveralls-image]][coveralls-url]\n\nA binding layer between React and TypeScript for the `React.createClass` syntax. With React 0.13, you can use ES6 classes to inherit from React components. This works well with TypeScript and you can just use the [type definitions][type-definitions] in DefinitelyTyped. The inheritance path has some different functionality so you may still want to use the `React.createClass` pattern. TypedReact can help you implement that pattern by providing a dummy parent class and a set of functions to appropriately extract the prototype for `React.createClass`\n\n## Installation\n\n```sh\nnpm install typed-react --save\n```\n\n## Example\n\n```ts\n/// \u003creference path='../path/to/react.d.ts' /\u003e\n/// \u003creference path='../path/to/typed-react.d.ts' /\u003e\n\nimport React = require(\"react\");\nimport TypedReact = require(\"typed-react\");\n\nexport interface TimerProps {\n    tickInterval: number;\n}\n\ninterface TimerState {\n    ticksElapsed: number;\n}\n\nclass Timer extends TypedReact.Component\u003cTimerProps, TimerState\u003e {\n    private interval: number;\n\n    getInitialState() {\n        return {\n            ticksElapsed: 0\n        };\n    }\n\n    tick() {\n        this.setState({\n            ticksElapsed: this.state.ticksElapsed + 1\n        });\n    }\n\n    componentDidMount() {\n        this.interval = setInterval(this.tick, this.props.tickInterval);\n    }\n\n    componentWillUnmount() {\n        clearInterval(this.interval);\n    }\n\n    render() {\n        return React.DOM.div(null, \"Ticks Elapsed: \", this.state.ticksElapsed);\n    }\n}\n\nexport var timer = TypedReact.createClass(Timer);\n```\n\nIn this case we export the Props and the Factory but we could make the props and state inline interfaces and just export the factory function.\n\n## Mixins\n\nTypedReact supports using existing React Mixins as well as defining new mixins with idiomatic TypeScript. The example is based on [http://www.typescriptlang.org/Handbook#mixins](http://www.typescriptlang.org/Handbook#mixins). You need to use `createMixin` on your own mixins and should export that from your mixin modules.\n\n```ts\n/// \u003creference path='../path/to/react.d.ts' /\u003e\n/// \u003creference path='../path/to/typed-react.d.ts' /\u003e\n\nimport React = require(\"react/addons\");\nimport TypedReact = require(\"typed-react\");\n\nexport interface GreeterProps {\n    name: string;\n}\n\nclass GreetingMixin extends TypedReact.Mixin\u003cGreeterProps, {}\u003e {\n    greet(greeting: string): React.ReactHTMLElement {\n        return React.DOM.h1(null, greeting, this.props.name);\n    }\n}\n\nclass Greeter extends TypedReact.Component\u003cGreeterProps, {}\u003e implements GreetingMixin {\n    greet: (greeting: string) =\u003e React.ReactHTMLElement;\n\n    render() {\n        return this.greet(this.greeting);\n    }\n}\n\nexport var greeter = TypedReact.createClass(Greeter, [\n    TypedReact.createMixin(GreetingMixin),\n    React.addons.PureRenderMixin\n]);\n```\n\n## Changelog\n\n- **3.3** Updating the React type definitions and moving the location of the type definition\n- **3.2** Update with new `react.d.ts` typings\n- **3.1** `extractPrototype` is now `createMixin`\n- **3.0** Idiomatic Mixin Support\n- **2.2** Making React a peer dependency. This means you do not need to pass `React.createClass` into `createClass`.\n- **2.1** Switching to createClass\n- **2.0** React 0.12.RC\n- **1.4** Removed incorrect mixin support\n- **1.3** Mixins\n\n## Development Setup\n\n```sh\ngit clone git@github.com:Asana/typed-react.git\ncd typed-react\nnpm install\nnpm run typings\nnpm test\n```\n\n[npm-url]: https://www.npmjs.org/package/typed-react\n[npm-image]: http://img.shields.io/npm/v/typed-react.svg?style=flat-square\n\n[travis-url]: http://travis-ci.org/Asana/typed-react\n[travis-image]: http://img.shields.io/travis/Asana/typed-react/master.svg?style=flat-square\n\n[coveralls-url]: https://coveralls.io/r/Asana/typed-react\n[coveralls-image]: https://img.shields.io/coveralls/Asana/typed-react/master.svg?style=flat-square\n\n[type-definitions]: https://github.com/borisyankov/DefinitelyTyped/tree/master/react\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAsana%2Ftyped-react","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAsana%2Ftyped-react","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAsana%2Ftyped-react/lists"}