https://www.npmjs.com/package/react-gridlines
image.png
install

  1. yarn add react-gridlines

GridLine组件

  1. import React from 'react';
  2. import GridLines from 'react-gridlines';
  3. function GridLine() {
  4. return (
  5. <GridLines
  6. className="vh100"
  7. cellWidth={40}
  8. strokeWidth={1}
  9. cellWidth2={8}
  10. lineColor="rgba(24,144,255,.7)"
  11. // lineColor2='#90f' 网格的颜色
  12. />
  13. );
  14. }
  15. export default GridLine;

【注意】不能使用 style设置样式,否则会覆盖默认的背景

css

  1. .vh100 {
  2. height: 100%;
  3. }

像素网格

渲染正方形网格到webgl画布

  1. npm install react-pixel-grid

image.png

  1. import PixelGrid from "react-pixel-grid";
  2. <PixelGrid
  3. data={Array(64).fill(0).map(Math.random)}
  4. options={{
  5. size: 10,
  6. padding: 2,
  7. background: [0, 0.5, 1],
  8. }}
  9. />