项目作者: cool-hooks

项目描述 :
🔗 Bitly implementation to React hook
高级语言: TypeScript
项目地址: git://github.com/cool-hooks/react-shorten-url.git
创建时间: 2020-05-23T20:46:40Z
项目社区:https://github.com/cool-hooks/react-shorten-url

开源协议:MIT License

下载


react-shorten-url

NPM version
NPM downloads
NPM license
Codecov
Travis
Bundle size

About

Bitly implementation to React hook

Demo

Playground – play with the library in CodeSandbox

Similar Projects

How to Install

First, install the library in your project by npm:

  1. $ npm install react-shorten-url

Or Yarn:

  1. $ yarn add react-shorten-url

Getting Started

ShortenUrlProvider

Config Param Values

Name Type Default Description
accessToken string Bitly access token
options BitlyConfig {} Additional Bitly config

useShortenUrl

Options

Name Type Default Description
url string URL to shorten

Returned Values

Name Type Description
loading boolean Is data loading
error Error Error shortening URL
data BitlyLink Data returned from Bitly

Example

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

  1. // index.js
  2. import React from 'react';
  3. import ReactDOM from 'react-dom';
  4. import { ShortenUrlProvider } from 'react-shorten-url';
  5. import App from './App';
  6. ReactDOM.render(
  7. <ShortenUrlProvider config={{ accessToken: 'bitly_access_token' }}>
  8. <App ></App>
  9. </ShortenUrlProvider>,
  10. document.getElementById('root')
  11. );

• Then use useShortenUrl Hook:

  1. // App.js
  2. import React from 'react';
  3. import { useShortenUrl } from 'react-shorten-url';
  4. const App = () => {
  5. const { loading, error, data } = useShortenUrl('https://example.com/');
  6. if (loading) return <p>Loading...</p>;
  7. if (error) return <p>Something went wrong</p>;
  8. return <h1>{data.link}</h1>;
  9. };
  10. export default App;

License

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