How can I use Fabric.js with React?

后端 未结 5 549
被撕碎了的回忆
被撕碎了的回忆 2020-12-04 15:31

I have an application using heavily HTML5 canvas via Fabric.js. The app is written on top of Angular 1.x, and I am planning to migrate it to React. My app allows writing tex

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-04 16:01

    There is also react-fabricjs package which allows you to use fabric objects as react components. Actually, Rishat's answer includes this package, but I don't understand how it is supposed to work as there is no 'fabric' object in the react-fabricjs (he probably meant 'fabric-webpack' package). An example for simple 'Hello world' component:

    import React from 'react';
    import {Canvas, Text} from 'react-fabricjs';
    
    const HelloFabric = React.createClass({
      render: function() {
        return (
          
              
          
        );
      }
    });
    
    export default HelloFabric;

    Even if you don't want to use this package, exploring it's code might help you to understand how to implement Fabric.js in React by yourself.

提交回复
热议问题