react-shorten-url
About
Bitly implementation to React hook
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
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:
// index.js ;;; ; ReactDOM;
• Then use useShortenUrl
Hook:
// App.js ;; const App = { const loading error data = ; if loading return <p>Loading...</p>; if error return <p>Something went wrong</p>; return <h1>datalink</h1>;}; ;
License
This project is licensed under the MIT License © 2020-present Jakub Biesiada