Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ReactStringReplace Component #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DerGoogler
Copy link

@DerGoogler DerGoogler commented Sep 23, 2022

Here is an example how it could works

import * as React from "react";
import { ReactStringReplace, ReactStringReplaceRules } from "react-string-replace";

function App() {
  const rules: ReactStringReplaceRules = [
    {
      search: /(https?:\/\/\S+)/g,
      onMatch(match, index) {
        return (
          <a key={match + index} href={match}>
            {match}
          </a>
        );
      },
    },
    {
      search: /@(\w+)/g,
      onMatch(match, index) {
        return (
          <a key={match + index} href={`https://twitter.com/${match}`}>
            @{match}
          </a>
        );
      },
    },
    {
      search: /#(\w+)/g,
      onMatch(match, index) {
        return (
          <a key={match + index} href={`https://twitter.com/hashtag/${match}`}>
            #{match}
          </a>
        );
      },
    },
  ];

  return (
    <div>
      <ReactStringReplace rules={rules}>
        Hey @ian_sinn, check out this link https://github.com/iansinnott/ Hope
        to see you at #reactconf
      </ReactStringReplace>
    </div>
  );
}

export default App;

@iansinnott
Copy link
Owner

hey thanks for this @DerGoogler. Changing the default export is bound to cause breakage, but could release this as v2.

If you add some testing for the new component to test.js I'd be happy to incorporate this. Also that will make sure the existing tests still run, since they use the default export.

(not to self, should add an action to run the tests for PRs)

@DerGoogler
Copy link
Author

@iansinnott,

I know this is a bad idea, this would break many libraries and app when update their dependencies..

@dzikoysk
Copy link

Is there any chance to get v2 with this change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants