Package Exports
- use-interpolate
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (use-interpolate) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
use-interpolate 📃
A react hook that interpolates tag into a component.
Install
npm i use-interpolateExample
import useInterpolate from 'use-interpolate'
function App(){
const vnode = useInterpolate(
'<0>name</0><1><2/></1>',
{
0: <span/>,
1: (children) => <p> - {children}</p>,
2: <Input theme='blue'/>,
}
)
return <div>{vnode}</div>
}output:
<div>
<span>name</span><p> - <Input theme='blue'/></p>
</div>API
useInterpolate(text, components)
A react hook that interpolates tag into a component.
createHook(options)
Create a custom interpolate hook.
options
tag
change tag bracket.
import {createHook} from 'use-interpolate'
const useInterpolate = createHook({ tag: ['{', '}'] })
function App(){
const vnode = useInterpolate(
'hello {0}world{/0}',
{
0: <span/>
}
)
return <div>{vnode}</div>
}output:
<div>
hello <span>world</span>
</div>strict
Default is true. If false, no error occurs.
const useInterpolate = createHook({ strict: false })
function App(){
const vnode = useInterpolate('<a>Invalid<b>', {a: <p/>, b: <br/>}) // no error.
/* ... */
}output:
<p>Invalid<br/></p>Related
- tag-name-parser - A tag parser that does not support attributes. Lightweight and fast.
License
MIT