Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add ReactStringReplace Component #81

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

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

Conversation

@DerGoogler
Copy link

@DerGoogler DerGoogler commented Sep 23, 2022
edited
Loading

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;

dzikoysk and ricardocanelas reacted with heart emoji
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 reacted with thumbs up emoji

Copy link
Author

@iansinnott,

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

Copy link

Is there any chance to get v2 with this change?

ricardocanelas reacted with eyes emoji

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /