GithubHelp home page GithubHelp logo

Comments (13)

steverecio avatar steverecio commented on May 14, 2024 47

Solution:

const componentDecorator = (href, text, key) => (
   <a href={href} key={key} target="_blank">
     {text}
   </a>
);

<Linkify componentDecorator={componentDecorator}>
   some user input http://github.com
</Linkify>

from react-linkify.

nodabladam avatar nodabladam commented on May 14, 2024 2

Thanks @steverecio, this solution saved the day! This is what I ended up with to get noopener and punycode going:

import punycode from "punycode";
...
const componentDecorator = (href, text, key) => (
   <a href={href} key={key} target="_blank" rel="noopener">
      {punycode.toASCII(text)}
  </a>
);
...
<Linkify componentDecorator={componentDecorator}>
   ...
</Linkify>

from react-linkify.

dlombardi avatar dlombardi commented on May 14, 2024 1

really could use the ability to set target to _blank 😬

from react-linkify.

sydinh avatar sydinh commented on May 14, 2024 1

@steverecio Really helpful. Many thanks

from react-linkify.

evoyy avatar evoyy commented on May 14, 2024 1

This bug was introduced in 1.0.0-alpha. Release 0.2.2 does not have this issue.

from react-linkify.

steverecio avatar steverecio commented on May 14, 2024

anybody find a solution?

from react-linkify.

LaurentiuCotaga avatar LaurentiuCotaga commented on May 14, 2024

@steverecio Good solution!

from react-linkify.

amandasavluchinske avatar amandasavluchinske commented on May 14, 2024

@steverecio Thank you!

from react-linkify.

mhemrg avatar mhemrg commented on May 14, 2024

#78 (comment)

from react-linkify.

seromenho avatar seromenho commented on May 14, 2024

Seems properties doesn't work at all. Maybe it's missing to pass them to the default componentDecorator.

from react-linkify.

dbudwin avatar dbudwin commented on May 14, 2024

You can create a decorator like some of the other comments here have mentioned. If you want to open new tabs securely, especially if the links are leaving the site you control, I suggest implementing the following:

TypeScript supported CodeSandbox: https://codesandbox.io/s/cool-montalcini-vkmtb?file=/src/App.tsx

npm install react-secure-link

...then...

import { SecureLink } from "react-secure-link"

<Linkify componentDecorator={(decoratedHref, decoratedText, key) => (
    <SecureLink href={decoratedHref} key={key}>{decoratedText}</SecureLink>
)}>
    Here is a link that will open securely in a new tab: www.github.com.
</Linkify>

from react-linkify.

steverecio avatar steverecio commented on May 14, 2024

@dbudwin is the gist here to add rel="noopener noreferrer" to the <a /> tags?

from react-linkify.

dbudwin avatar dbudwin commented on May 14, 2024

@steverecio yes, that's effectively what it does. Just abstracts away the "how" of creating a secure link in a new tab. Nothing fancy.

from react-linkify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.