1.0.5 • Published 3 years ago

react-shorten-url v1.0.5

Weekly downloads
43
License
MIT
Repository
github
Last release
3 years ago

react-shorten-url

NPM version NPM downloads NPM license Codecov Travis Bundle size

About

Bitly implementation to React hook

Similar Projects

How to Install

First, install the library in your project by npm:

$ npm install react-shorten-url

Or Yarn:

$ yarn add react-shorten-url

Getting Started

ShortenUrlProvider

Config Param Values

NameTypeDefaultDescription
accessTokenstringBitly access token
optionsBitlyConfig{}Additional Bitly config

useShortenUrl

Options

NameTypeDefaultDescription
urlstringURL to shorten

Returned Values

NameTypeDescription
loadingbooleanIs data loading
errorErrorError shortening URL
dataBitlyLinkData returned from Bitly

Example

• Import ShortenUrlProvider from library in your React app, wrap main component and set config values:

// index.js

import React from 'react';
import ReactDOM from 'react-dom';
import { ShortenUrlProvider } from 'react-shorten-url';

import App from './App';

ReactDOM.render(
  <ShortenUrlProvider config={{ accessToken: 'bitly_access_token' }}>
    <App />
  </ShortenUrlProvider>,
  document.getElementById('root')
);

• Then use useShortenUrl Hook:

// App.js

import React from 'react';
import { useShortenUrl } from 'react-shorten-url';

const App = () => {
  const { loading, error, data } = useShortenUrl('https://example.com/');

  if (loading) return <p>Loading...</p>;

  if (error) return <p>Something went wrong</p>;

  return <h1>{data.link}</h1>;
};

export default App;

License

This project is licensed under the MIT License © 2020-present Jakub Biesiada

1.1.0-alpha.1

3 years ago

1.1.0-alpha.0

3 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.0-beta.3

4 years ago

1.0.0-beta.2

4 years ago

1.0.0-beta.1

4 years ago