Skip to content

ys319/use-replace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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!
};

About

Replace string with component using RegExp.

Resources

License

Stars

Watchers

Forks

Packages

No packages published