Skylor Component
为你的 React 组件注入配置,如:Services
,Axios
, etc.
Install
npm install skylor-component
// or
yarn add skylor-component
Usage
在应用入口处注入:
import init from 'skylor-component';import Services from './services'; // eg: 你的服务... ; // 需要注入的项目
在任意组件内使用,建议全部使用
import React from 'react';import Component from 'skylor-component'; // 只需要这么一行就可以在组件内直接使用 `this`来获取注入的配置项。 state = username: '' async { const res = await thisServicesuser; this } { return <div>example: thisstateusername thisHello</div> ; }