marekdano / use-quote

A custom React hook that provides a random quote from QuoteGarden.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@marekdano/use-quote

A custom React hook that provides a random quote from QuoteGarden

NPM JavaScript Style Guide

Install

npm install --save @marekdano/use-quote

OR

yarn add @marekdano/use-quote

Usage

import React, { Component } from 'react'

import { useQuote } from '@marekdano/use-quote'

const Example = () => {
  const { quote, isLoading, isError } = useQuote()
  
  if (isLoading) return <p>Loading...</p>

  if (quote) {
    return (
      <>
        <p>{quote.text}</p>
        <p><i>{quote.author}</i></p>
      </>
    )
  }

  if (isError) return <p>Difficulty displaying a quote at the moment.</p>

  return null
}

License

MIT © marekdano


This hook is created using create-react-hook.

About

A custom React hook that provides a random quote from QuoteGarden.


Languages

Language:JavaScript 90.2%Language:HTML 8.6%Language:CSS 1.3%