@simplus/robin-react

This is a react docorator for Robin

Usage no npm install needed!

<script type="module">
  import simplusRobinReact from 'https://cdn.skypack.dev/@simplus/robin-react';
</script>

README

README

This is a react docorator for Robin

Install

To use the package install it with npm

npm install --save @simplus/robin-react

Usage

In jour main file

You need to have created your RobinProvider and give it to the RobinReact main class in order to make the binding between react and the robin library


//robins.jsx

import RobinReact from '@simplus/robin-react'
import {RobinProvider, CollectionRobin} from '@simplus/robin'

const robins = {
    aCollection : new CollectionRobin({ baseUrl : "/api/myCollection", })
}

const provider = new RobinProvider(robins)

RobinReact.setProvider(provider)

export {provider, robins}

Then you can use the decorator to bind robins to a component


//component.jsx

import * as React from 'react'

import {connectRobin} from '@simplus/robin-react'
import {provider, robins} from './robins.jsx'

@connectRobin([robins.aCollection])
class MyComponent extends React.Component{
    componentWillMount(){
        robins.aCollection.find({})
    }
    
    render(){
        return <div>
            {this.props.aCollection.collection.map(item => {
                return <div>{JSON.stringify(item)}</div>
            })}
        </div>
    }
}

export { MyComponent }

export default MyComponent

See robin for more info