项目作者: the-road-to-learn-react

项目描述 :
Custom hook to add a viewbox attribute to your SVG in case it's missing.
高级语言: JavaScript
项目地址: git://github.com/the-road-to-learn-react/use-with-viewbox.git
创建时间: 2019-06-26T08:02:03Z
项目社区:https://github.com/the-road-to-learn-react/use-with-viewbox

开源协议:MIT License

下载


useWithViewbox React Hook

Build Status Slack Greenkeeper badge NPM

Custom hook to add a viewbox attribute to your SVG in case it’s missing. It calculates the viewbox based on the rendered svg element with its height and width. Read more about it here.

Installation

npm install use-with-viewbox

Usage

  1. import useWithViewbox from 'use-with-viewbox';
  2. const MySvg = (props) => {
  3. const ref = React.createRef();
  4. useViewbox(ref);
  5. return (
  6. <svg ref={ref} {...props}>
  7. // SVG Content ...
  8. </svg>
  9. );
  10. };
  11. export default MySvg;

Contribute

  • git clone git@github.com:the-road-to-learn-react/use-with-viewbox.git
  • cd use-with-viewbox
  • npm install

More