{"id":21937612,"url":"https://github.com/cap32/react-input-component","last_synced_at":"2025-04-22T12:12:39.445Z","repository":{"id":65373075,"uuid":"85800130","full_name":"Cap32/react-input-component","owner":"Cap32","description":"🚀 A better alternative to react built-in input components","archived":false,"fork":false,"pushed_at":"2018-09-13T10:41:14.000Z","size":55,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-22T12:12:22.447Z","etag":null,"topics":["component","controlled","input","react","select","textarea","uncontrolled"],"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/Cap32.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-22T07:52:33.000Z","updated_at":"2023-03-04T05:34:31.000Z","dependencies_parsed_at":"2023-01-19T23:35:30.577Z","dependency_job_id":null,"html_url":"https://github.com/Cap32/react-input-component","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cap32%2Freact-input-component","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cap32%2Freact-input-component/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cap32%2Freact-input-component/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cap32%2Freact-input-component/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Cap32","download_url":"https://codeload.github.com/Cap32/react-input-component/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250237832,"owners_count":21397401,"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":["component","controlled","input","react","select","textarea","uncontrolled"],"created_at":"2024-11-29T01:20:44.104Z","updated_at":"2025-04-22T12:12:39.415Z","avatar_url":"https://github.com/Cap32.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-input-component\n\n[![CircleCI](https://circleci.com/gh/Cap32/react-input-component.svg?style=shield)](https://circleci.com/gh/Cap32/react-input-component) [![Build Status](https://travis-ci.org/Cap32/react-input-component.svg?branch=master)](https://travis-ci.org/Cap32/react-input-component)\n\n🚀 A better alternative to react built-in input components\n\n\n## Motivations\n\n1. Before use built-in react inputs, you may need to know what the hell are [controlled and uncontrolled inputs](https://goshakkk.name/controlled-vs-uncontrolled-inputs-react/)\n2. Controlled input has a [bug](https://github.com/facebook/react/issues/3926)\n3. Controlled input is slow\n4. Uncontrolled input is not powerful\n\nSo I created this module to avoid the problems above. \n\n\n## Installation\n\n```bash\nyarn add react-input-component\n```\n\n\n## Usages\n\nJust like built-in input components, but no `defaultValue` or `defaultChecked` prop.\n\n###### Example\n\n```js\nimport React from 'react';\nimport { Input } from 'react-input-component';\n\nexport default () =\u003e\n    \u003cInput value=\"feel free to type here...\" /\u003e\n```\n\n\n###### Components\n\n- Input\n- TextArea\n- Select\n\n\n## Notes\n\n- All styles are the same with react built-in inputs\n- All react built-in inputs' props are supported, except `defaultValue` and `defaultChecked`\n- To get the DOM, use `findDOMNode(input)` or `input.dom`. (This `input` refs to an `Input` instance, like `\u003cInput ref=\"input\" /\u003e`)\n- Form data (value or checked) would be handled by the DOM itself.\n- Form data could also be changed by passing new `value` prop to component.\n\n\n## Caveat\n\nIf the new `value` prop is equal to the prev `value` prop, form data would not be updated, even if form data is not equal to the `value` prop.\n\n```js\nimport React, { Component } from 'react';\nimport { render, findDOMNode } from 'react-dom';\nimport { Input } from 'react-input-component';\n\nclass Bad extends Component {\n    state = { value: 'a' };\n\n    componentDidMount() {\n        findDOMNode(this).value = 'b'; // Simulate user typing\n\n        // Try to reset `value` to \"a\", but failed\n        // Because the new `value` prop is equal to the prev `value` prop\n        this.setState({ value: 'a' }); // =\u003e BAD\n    }\n\n    render() {\n        return (\u003cInput {...this.state} /\u003e);\n    }\n}\n\nrender(\u003cBad /\u003e, document.getElementById('root'));\n```\n\nTo resolve this problem, you could change the DOM value directly, or add a special `updateKey` prop.\n\n`updateKey` helps Input component to decide to update. If `updateKey` changes, form data changes.\n\n```js\nimport React, { Component } from 'react';\nimport { render, findDOMNode } from 'react-dom';\nimport { Input } from 'react-input-component';\n\nclass Good extends Component {\n    state = { value: 'a' };\n\n    componentDidMount() {\n        findDOMNode(this).value = 'b'; // Simulate user typing\n\n        // Try to reset `value` to \"a\"\n        // Adding a new `updateKey` to force upate\n        this.setState({ value: 'a', updateKey: Math.random() }); // =\u003e GOOD\n    }\n\n    render() {\n        return (\u003cInput {...this.state} /\u003e);\n    }\n}\n\nrender(\u003cGood /\u003e, document.getElementById('root'));\n```\n\n\n## License\n\nMIT © Cap32\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcap32%2Freact-input-component","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcap32%2Freact-input-component","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcap32%2Freact-input-component/lists"}