bind-with-arguments
彻底解决React
事件绑定中this
和参数的问题
usage
npm install bind-with-arguments --save
import React Component from 'react';import bindWithArguments from 'bind-with-arguments'; async { // fetch } // 异步函数并且有参数 @bindWithArguments async { const detail = await this; // ... } // 异步函数并且无参数 @bindWithArguments async { // fetch this; } // 同步函数并且有参数 @bindWithArguments { if id && name this; } // 同步函数并且有参数 @bindWithArguments { const yyy = thisstate; if yyy === 'zzz' this; } { const list = thisstate; return <div ='warapper'> list <button =>异步函数并且无参数</button> <button =>同步函数并且有参数</button> </div> }