remax/macro 下包含的是基于 babel-plugin-macros 的宏。
带有 ? 的选项表示非必填项
App 生命周期 hook
import { useAppEvent } from 'remax/macro';...useAppEvent('onShow', () => {console.log('on show');})
Page 生命周期 hook
import { usePageEvent } from 'remax/macro';...usePageEvent('onShow', () => {console.log('on show');})
eventName 生命周期名称callback 回调函数,各个生命周期回调函数的具体签名,参考各个平台对应的文档。无
eventName 生命周期名称callback 回调函数,各个生命周期回调函数的具体签名,参考各个平台对应的文档。无
注册基础组件
import { createHostComponent } from 'remax/macro';// 假设微信提供了一个 Remax 还没有支持的新组件 custom-view,则可以通过 createHostComponent 创建:const CustomView = createHostComponent('custom-view', ['prop',// 支持传入一个数组来做属性别名['class', 'className'],]);...<CustomView prop="" className=" />
name 基础组件名称props 基础组件拥有的属性名称列表['class', 'className'],表示在 remax 中用 className 代替 class返回一个封装后的 React 组件。
引入插件方法,与原生 requirePlugin 相同
import { requirePlugin } from 'remax/macro';const Plugin = requirePlugin('plugin://xxxx');
name 插件名称返回一个原生插件对象
引入插件组件,与原生 requirePlugin 相同
import { requirePluginComponent } from 'remax/macro';const PluginComponent = requirePluginComponent('plugin://xxxx');...<PluginComponent />
name 插件组件名称返回一个封装好的 React 组件