@ys319/use-replace
v0.0.4
Published
Replace string with component using RegExp.
Downloads
2
Readme
useReplace
React hook for Replace string with component using regexp.
Example
import { MatchRenderer, useReplace } from "@ys319/use-replace";
const Highlight: MatchRenderer = ({ matches: [match] }) => `[${match}]`;
const App = () => {
const replace = useReplace(/replacer?/ig);
return (
<p>
{replace("React RegExp Replacer!", Highlight)}
<br />
{replace("This is very simple replacer hook.", Highlight)}
<br />
{replace("Let's RePLaCe it!", Highlight)}
</p>
);
// Output:
// > React RegExp [Replacer]!
// > This is very simple [replacer] hook.
// > Let's [RePLaCe] it!
};