React 吉他(Guitar)
made with
React
简介及使用教程
React 吉他(Guitar)是一个基于React的漂亮且自适应的吉他组件,可以自定义吉他的调谐、品数、左右手等。
安装
Npm
npm i react-guitar
Yarn
yarn add react-guitar
使用
引入组件
import React from 'react'
import { render } from 'react-dom'
import Guitar from 'react-guitar'
渲染
render(
<Guitar strings={[0, 1, 2, 2, 0, -1]} />,
document.getElementById('root')
)
使用useSound
钩子自定义声音
import Guitar, { useSound } from 'react-guitar'
import E2 from 'react-guitar/resources/E2.mp3'
import D3 from 'react-guitar/resources/D3.mp3'
import G3 from 'react-guitar/resources/G3.mp3'
import E4 from 'react-guitar/resources/E4.mp3'
...
const { play, strum } = useSound({ E2, D3, G3, E4 }, strings, tuning)
<Guitar strings={strings} onPlay={play}/>
...
示例
作者
Alejandro Tardín
@4lejandrito相关项目