{"id":17463568,"url":"https://github.com/rosszurowski/react-responsive-canvas","last_synced_at":"2025-10-10T07:09:01.168Z","repository":{"id":57343575,"uuid":"143684670","full_name":"rosszurowski/react-responsive-canvas","owner":"rosszurowski","description":"Fit a canvas element to its parent","archived":false,"fork":false,"pushed_at":"2018-08-30T17:04:53.000Z","size":25,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-25T16:51:36.587Z","etag":null,"topics":["canvas","react","responsive"],"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/rosszurowski.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":"2018-08-06T06:18:45.000Z","updated_at":"2024-08-15T08:42:54.000Z","dependencies_parsed_at":"2022-09-12T07:00:35.426Z","dependency_job_id":null,"html_url":"https://github.com/rosszurowski/react-responsive-canvas","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosszurowski%2Freact-responsive-canvas","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosszurowski%2Freact-responsive-canvas/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosszurowski%2Freact-responsive-canvas/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosszurowski%2Freact-responsive-canvas/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rosszurowski","download_url":"https://codeload.github.com/rosszurowski/react-responsive-canvas/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231544341,"owners_count":18392999,"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":["canvas","react","responsive"],"created_at":"2024-10-18T10:24:24.450Z","updated_at":"2025-10-10T07:09:01.096Z","avatar_url":"https://github.com/rosszurowski.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-responsive-canvas\n\n[![npm](https://badgen.now.sh/npm/v/react-responsive-canvas)](https://www.npmjs.com/package/react-responsive-canvas)\n\nSimple React component for a canvas that fits the size of its parent.\n\n## Installation\n\n```\nnpm install --save react-responsive-canvas\n```\n\n## Usage\n\n#### Props\n\n* `canvasRef: (el: HTMLCanvasElement) =\u003e void` - A [ref callback function](https://reactjs.org/docs/refs-and-the-dom.html#callback-refs) to set a reference to the `canvas` element\n* `onResize: () =\u003e void` - A callback for when the canvas resizes\n* `scale: number` - A ratio to scale the canvas by. Used to support high-quality canvases on retina screens. Defaults to `window.devicePixelRatio`\n\n#### Example\n\n```jsx\nimport Canvas from 'react-responsive-canvas';\n\nclass App extends Component {\n  componentDidMount() {\n    this.ctx = this.canvas.getContext('2d');\n    this.draw();\n  }\n\n  draw() {\n    // Draw whatever\n    this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);\n  }\n\n  render () {\n    return (\n      \u003cdiv\u003e\n        \u003cCanvas\n          canvasRef={el =\u003e (this.canvas = el)}\n          onResize={this.draw} /\u003e\n      \u003c/div\u003e\n    );\n  }\n}\n```\n\n## Context\n\nBy default, HTML `\u003ccanvas /\u003e` elements are a fixed size. When creating animated canvas graphics, I usually want the canvas to take the shape of the container it sits in — whether that's the whole page, or a header image.\n\nAfter writing this component too many times using [hughsk/canvas-fit](https://github.com/hughsk/canvas-fit), I built this module.\n\nIt auto-resizes the canvas to fill it's container, and by default scales the canvas to match the user's screen resolution (ie. regular vs. retina screens).\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frosszurowski%2Freact-responsive-canvas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frosszurowski%2Freact-responsive-canvas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frosszurowski%2Freact-responsive-canvas/lists"}