Skip to content

marekdano/use-quote

Repository files navigation

@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.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published