UNPKG

@arhamill/cortex

Version:
57 lines (47 loc) 1.49 kB
# Cortex: A reactive library for the Corda vault ### Guide to usage Install cortex ``` npm install @arhamill/cortex ``` Run the [cortex webserver](https://github.com/arhamill/cortex-server) ``` docker run -p 8080:8080 -v "<cordapp-directory>":/opt/cortex/cordapps arhamill/cortex ``` Create a corda context and provider component ``` import { createLinearContext } from '@arhamill/cortex' const nft = createLinearContext('http://cortex-server-url', 'com.r3.corda.lib.tokens.contracts.states.NonFungibleToken') const nftContext = nft.linearContext const NFTProvider = nft.LinearProvider ``` Add the provider as a parent to any component that needs to consume it (either within itself or any of its children). For convenience this will usually be the `App` component. ``` ReactDOM.render( <NFTProvider> <App /> </NFTProvider> , document.getElementById('root')); ``` Consume the context from any child component! ``` import React, { useContext } from 'react' const MyComponent = () => { const nfts = useContext(nftContext) ... } ``` Any component consuming this context will be re-rendered when there is a vault update. ## Full API documentation Create a context provider for token-sdk fungible tokens: ``` createTokensContext(url) ``` Create a context provider for any linear state (order of linear ids is preserved): ``` createLinearContext(url, stateClass) ``` Create a context provider for any contract state: ``` createStateContext(url, stateClass) ```