redwood-p2p-client
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

Redwood.js

Redwood client

WIP

React hooks

import React, { useRef } from 'react'
import Redwood from 'redwood'
import { RedwoodProvider, useRedwood, useStateTree } from 'redwood/react'

const identity = Redwood.identity.random()

function App() {
    return (
        <RedwoodProvider
            httpHost="http://localhost:8080"
            webrtc={true}
            identity={identity}
        >
            <ChatRoom />
        </RedwoodProvider>
    )
}

function ChatRoom() {
    const { redwoodClient } = useRedwood()
    const chatRoom = useStateTree('chat.redwood.dev/general')
    const textInput = useRef()

    function onClickSend() {
        redwoodClient.put({
            patches: [
                '.messages[-0:-0] = ' + Redwood.utils.JSON.stringify({
                    sender: identity.address,
                    text:   textInput.current.value,
                }),
            ],
        })
    }

    return (
        <div>
            {chatRoom.messages.map(msg => (
                <div>
                    <div>{msg.sender}</div>
                    <div>{msg.text}</div>
                </div>
            ))}

            <input ref={textInput} />
            <button onClick={onClickSend}>Send</button>
        </div>
    )
}

Readme

Keywords

Package Sidebar

Install

npm i redwood-p2p-client

Weekly Downloads

0

Version

0.1.0

License

MIT

Unpacked Size

3.3 MB

Total Files

85

Last publish

Collaborators

  • bryn