• Stars
    star
    155
  • Rank 240,864 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A React library that generates beautiful previews for your links.

React Link Preview

A React component that renders beautiful, fully-customizable link previews.

Demo Follow @dhaiwat10 npm version package downloads CI

Demo

How to use

Install the package:

yarn add @dhaiwat10/react-link-preview

npm install @dhaiwat10/react-link-preview

Import and render the preview:

import { LinkPreview } from '@dhaiwat10/react-link-preview';

const Home = () => {
  return <LinkPreview url='https://www.youtube.com/watch?v=dQw4w9WgXcQ' width='400px' />;
};

If the component renders nothing, it means that no metadata could be scraped for the URL. Provide a fallback component if you don't want to render null.

Important

This package uses a Heroku proxy (open-source) to get around CORS issues. The public proxy receives a lot of traffic (+ there is a rate limit) and is not recommended for production use.

Recommended workflow (for production)

  • Please fork the proxy repo and host your own copy of it.
  • You can then use the customFetcher prop to pass a fetcher function that fetches data from your proxy. The LinkPreview will now use your proxy as the data source. More details below.

API (Available props)

You can pass the following props to the LinkPreview component.

url (string)

The URL for which you want to generate the link preview.


customFetcher? (function)

A function that takes in a url & fetches data from a proxy/server. The function should return a Promise that resolves to an object with the following structure:

{
  title: string | null;
  description: string | null;
  image: string | null;
  siteName: string | null;
  hostname: string | null;
}

You can use any data-source as you like as long as the customFetcher function returns a Promise that resolves to an object with the above structure.

Example


fallback? (JSX.Element / any valid JSX)

A fallback component which will be rendered if a link preview could not be generated.


fallbackImageSrc (string)

A fallback image src/URL which will be used if there was no image found for the URL.

explicitImageSrc (string)

The src that will be used for the image regardless of what the data source returns.

showLoader? (boolean)

Whether you want to display the default loading skeleton or not.


customLoader? (JSX.Element / any valid JSX)

Custom loader that will be displayed in place of the default loader.


backgroundColor? (string)

Background color of the card.


primaryTextColor? (string)

Color of the primary text (title).


secondaryTextColor? (string)

Color of the secondary text (description, URL, domain name).


borderColor? (string)

Color of the border of the card.


className? (string)

Any custom CSS class that you want to apply to the card.


width? (string or number)

Width of the card.


height? (string or number)

Height of the card.


margin? (string or number)

Margin around the card.


descriptionLength? (number)

Length of the description in the card. (number of characters)


borderRadius? (string or number)

Border radius of the card.


imageHeight? (string or number)

Height of the image.


textAlign? ( left, right or center)

Alignment of the text.


openInNewTab? (boolean)

Where the link is opened (new tab or current tab).


showPlaceholderIfNoImage? (boolean)

Whether the placeholder image is displayed in case no image could be scraped.


Props marked with ? are optional.

More Repositories

1

create-web3-frontend

The fastest way to get started with a fully-fledged web3 frontend
TypeScript
174
star
2

rlp-proxy

The proxy used by @dhaiwat10/react-link-preview to fetch metadata for URLs.
TypeScript
34
star
3

priv-key-precommit

A simple precommit hook that checks for the presence of an Ethereum private key in your codebase
TypeScript
29
star
4

react-ipfs-image

TypeScript
21
star
5

svelte-link-preview

Svelte port of @dhaiwat10/react-link-preview
Svelte
15
star
6

rainbowkit-nft-mint-vite

TypeScript
13
star
7

dhaiwat.xyz

TypeScript
12
star
8

siwe-tutorial

TypeScript
12
star
9

optimism-rentable-nfts

Rentable NFTs on Optimism 🔴
Solidity
11
star
10

repo-backup-arweave

(WIP) A GitHub action that backs up your repo's source code to Arweave.
TypeScript
10
star
11

web3-million-dollar-page

Solidity
10
star
12

furniture-exchange

2021 Supabase launchweek hackathon entry
JavaScript
8
star
13

nextjs-ts-tailwind-eslint-prettier-starter

Starter code for a React project initialized with NextJS, TypeScript, Tailwind, Prettier & ESLint.
JavaScript
7
star
14

nft-minting-page

WBW3 wagmi workshop
TypeScript
6
star
15

streamr-react-starterkit

CSS
6
star
16

rpc-comparison

An app that compares the performance of major RPC providers in terms of speed.
TypeScript
6
star
17

ropsten-faucet

An ether faucet running on the Ropsten test network. Written with Hardhat, Solidity, TypeScript, React, NextJS.
TypeScript
6
star
18

react-agora

Plug-and-play React wrapper for AgoraRTC.
TypeScript
5
star
19

zora-nft-historical-explorer

TypeScript
5
star
20

aadhar-guardian

TypeScript
5
star
21

repo-backup-ipfs

A GitHub action that backs up your repo's source code to IPFS.
TypeScript
4
star
22

zenquotes

A discord bot that delivers positivity to your server.
TypeScript
4
star
23

next-chakra-rainbowkit-wagmi-starter

JavaScript
3
star
24

devdao-domains

.devdao
Solidity
3
star
25

rentable-nft-gated-frontend

TypeScript
3
star
26

isolated-react-component-testing

TypeScript
3
star
27

react-query-tutorial

JavaScript
3
star
28

clean-twitter

Chrome extension that removes all the annoying clutter from Twitter.
JavaScript
3
star
29

arweave-repo-backup-gh-action

(WIP) A GitHub Action that automatically backs up your repo's source code to Arweave
TypeScript
3
star
30

vite-arweave

JavaScript
3
star
31

fast-rpc-picker

A simple Node.js script that picks the fastest RPC endpoint out of a given list.
TypeScript
2
star
32

fuel-dapp-template

fuel-dapp-template
TypeScript
2
star
33

create-fuel-dapp

TypeScript
2
star
34

rainbowkit-nft-mint

TypeScript
2
star
35

eth-utils-raycast

A Raycast extension port of eth-utils.com
TypeScript
2
star
36

lens-frontend

JavaScript
2
star
37

vyper-counter-contract

Python
2
star
38

foundry-simple-nft

Solidity
2
star
39

scaffold-eth-zora-zdk

TypeScript
2
star
40

simple-nft

TypeScript
2
star
41

streamr-lens-group-chat

TypeScript
2
star
42

ankr-rpc-health

TypeScript
2
star
43

ts-fps-game

ts-fps-game
TypeScript
2
star
44

developer-dao-yearbook

TypeScript
2
star
45

typescript-action-template

TypeScript
1
star
46

defidashboard-test

TypeScript
1
star
47

ankrjs-react-quickstart

TypeScript
1
star
48

sol-escrow

Rust
1
star
49

fuel-sdk-browser-test

CSS
1
star
50

react-search-demo

search-demo
TypeScript
1
star
51

discord-cleaner

TypeScript
1
star
52

generative-nft-factory

TypeScript
1
star
53

coin-flip-farcaster-frame

A Farcaster Frame that lets you flip a coin
TypeScript
1
star
54

node-playground

TypeScript
1
star
55

fuel-node-ts-playground

TypeScript
1
star
56

fuel-contract-balance

TypeScript
1
star
57

lottery-eth-frontend

JavaScript
1
star
58

Dhaiwat10

1
star
59

fuel-deposit-withdraw-ts-cookbook-example

TypeScript
1
star
60

onchain-activity-visualizer

onchain-activity-visualizer
TypeScript
1
star
61

ankrjs-node-quickstart

TypeScript
1
star
62

scaffold-fuel

TypeScript
1
star
63

ts-to-js-browser

A simple example showing how to transpile & execute TypeScript inside the browser.
HTML
1
star
64

ecommerce-aggregator

JavaScript
1
star
65

my-fuel-dapp

TypeScript
1
star
66

url-shortener-backend

Backend of my URL shortener project written with Node.js and Express.js.
JavaScript
1
star
67

dummy-repo

1
star
68

node-ts-template

TypeScript
1
star
69

simple-nft-old

TypeScript
1
star
70

gh-action-debug

JavaScript
1
star
71

ts-sandbox

An extremely simple TypeScript sandbox. Runs & executes completely in the browser.
JavaScript
1
star
72

fuel-wallet-react-test

fuel-wallet-react-test
TypeScript
1
star
73

fuel-ts-scripts

TypeScript
1
star
74

gho-bank

TypeScript
1
star
75

ecom-agg

SSIP Hackathon Final 2021
TypeScript
1
star