react-hook-post-robot
It's easy to use "robot-post" on React's components.
Install
npm install --save react-hook-post-robot
Usage
import React useEffect useState from 'react'import usePostRobotOn usePostRobotSend PostRobotContext from 'react-hook-post-robot' const SampleComponentParent = props // In fact, you can specify an contentWindow of iframe. // You can fix the window under the Context. return <PostRobotContext.Provider = /> const SampleComponentChild = const state setState = // Instead of postRobot.on('test', () => message) // Instead of postRobot.send('test', ({ data }) => setState(data)) const sender = return <>state</> const App = return <SampleComponentParent> <SampleComponentChild /> </SampleComponentParent>
License
MIT © aiji42
Inspiration
This library is inspired by:
This hook is created using create-react-hook.