This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

react-hook-post-robot

1.0.1 • Public • Published

react-hook-post-robot

It's easy to use "robot-post" on React's components.

NPM JavaScript Style Guide

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 value={{ window }} {...props} />
}
 
const SampleComponentChild = () => {
  const [state, setState] = useState(null)
 
  // Instead of postRobot.on('test', () => message)
  usePostRobotOn('test', () => {
    return 'Hello, react-hook-post-robot!'
  }, [])
 
  // Instead of postRobot.send('test', ({ data }) => setState(data))
  const sender = usePostRobotSend('test')
  useEffect(() => {
    sender().then(({ data }) => setState(data))
  }, [])
 
  return (
    <>{state}</>
  )
}
 
const App = () => {
  return (
    <SampleComponentParent>
      <SampleComponentChild />
    </SampleComponentParent>
  )
}
 
export default App

License

MIT © aiji42

Inspiration

This library is inspired by:


This hook is created using create-react-hook.

Readme

Keywords

none

Package Sidebar

Install

npm i react-hook-post-robot

Weekly Downloads

4

Version

1.0.1

License

MIT

Unpacked Size

217 kB

Total Files

25

Last publish

Collaborators

  • aiji42