Skip to main content

farrow-react

React adapter for farrow-http

Installation#

# via npm
npm install --save farrow-react
# via yarn
yarn add farrow-react

API#

// farrow-hooks for rendering react component
import { useReactView } from 'farrow-react'
// react component for auto prefix
import { Link } from 'farrow-react/Link'
import {
// react-hooks version of usePrefix
usePrefix,
// access current render context
useRenderContext,
} from 'farrow-react/hooks'
// ReactContext for rendering
import { ReactRenderContext } from 'farrow-react/Context'

useReactView (options?: ReactViewOptions) => { render(element: JSX.Element): Http.Response}#

use react for rendering

type ReactResponseOptions = {
// config doctype
docType?: string
}
type ReactViewOptions = ReactResponseOptions & {
// use stream or string
useStream?: boolean
}
type ReactView = {
// render react element to farrow http response
render: <T extends JSX.Element>(element: T) => Http.Response
}

usePrefix(): string#

const Test = () => {
let prefix = usePrefix()
return <div>{prefix}</div>
}

useRenderContext(): string#

type ReactRenderContext = {
// basenames taken from farrow-http
basenames: string[]
}
const Test = () => {
let renderContext = useRenderContext()
return <div>{renderContext.basenames.join('')}</div>
}

Link#

// Link's props is equal to <a />
<Link href="/">a link</Link>