1.0.3-rc1 • Published 3 years ago

react-fakers v1.0.3-rc1

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

React Fakers

React Fakers is a collection of dummy data from the most popular dummy data providers such as Json Place Holder, Faker, Pokemon, etc, for application development testing.

Build Status npm version npm bundle size npm bundle size (version) Snyk Vulnerabilities for GitHub Repo npm Open Source Helpers PRs Welcome

TABLE OF CONTENT

INSTALLATION

npm i react-fakers | yarn add react-fakers

EXAMPLE USAGE

  • Hooks

    • useFaker
    import React, { useState, useEffect } from 'react'
    import { useFaker } from 'react-fakers'
    
    const App = () => {
      const { success, error, loading } = useFaker()
    
      if (error) {
        alert(error.message)
      }
    
      return (
        <>
          {!loading && <h4>Loading....</h4>}
          <ul>
            {loading &&
              success.map((val, id) => (
                <li key={val.uuid}>
                  {val.firstname} {val.lastname} - {val.email}
                </li>
              ))}
          </ul>
        </>
      )
    }
    
    export default App
    • useFaker With Params
    import React, { useState, useEffect } from 'react'
    import { useFaker } from 'react-fakers'
    
    const App = () => {
    
      const { success, error, loading } = useFaker({
        type: 'addresses',
        params: { addresses: { quantity: 5 } }
      })
    
      if (error) {
        alert(error.message)
      }
    
      return (
          <>
          {!loading && <h4>Loading....</h4>}
           <ul>
            {loading &&
              success.map((val, id) => (
                <li key={val.uuid}>
                  {val.firstname} {val.lastname} - {val.email}
                </li>
              ))}
          </ul>
        </>
      )
    }
    
    export default App
    • useJsonPlaceHolder
    import React, { useState, useEffect } from 'react'
    import { useJsonPlaceHolder } from 'react-fakers'
    
    const App = () => {
    
      const { success, error, loading } = useJsonPlaceHolder()
    
      if (error) {
        alert(error.message)
      }
    
      return (
        <>
          {!loading && <h4>Loading....</h4>}
           <ul>
            {loading &&
              success.map((val, id) => (
                <li key={id}>
                  {val.name} - {val.email}
                </li>
              ))}
          </ul>
        </>
      )
    }
    
    export default App
    • useJsonPlaceHolder With Params
    import React, { useState, useEffect } from 'react'
    import { useJsonPlaceHolder } from 'react-fakers'
    
    const App = () => {
    
      const { success, error, loading } = useJsonPlaceHolder({
        type: 'posts',
        params: { posts: { userId: 1 } },
        options: { limit: 3 }
      })
    
      if (error) {
        alert(error.message)
      }
    
      return (
        <>
          {!loading && <h4>Loading....</h4>}
           <ul>
            {loading &&
              success.map((val, id) => (
                <li key={id}>
                  {val.id} - {val.title}
                </li>
              ))}
          </ul>
        </>
      )
    }
    
    export default App
  • Components

    • Faker
    import React, { Component } from 'react'
    import { Faker } from 'react-fakers'
    
    class App extends Component {
      constructor(props) {
        super(props)
        this.state = {
          loading: false,
          data: []
        }
      }
    
      onSuccess = (res) => {
        this.setState({
          loading: true,
          data: res
        })
      }
    
      onError = (error) => {
        if (error) {
          alert(error.message)
        }
      }
    
      render() {
        return (
          <>
            <Faker success={this.onSuccess} error={this.onError} />
    
             {!this.state.loading && <h4>Loading....</h4>}
              <ul>
                {this.state.loading &&
                  this.state.data.map((val, id) => (
                    <li key={val.uuid}>
                      {val.firstname} {val.lastname} - {val.email}
                    </li>
                  ))}
             </ul>
          </>
        )
      }
    }
    
    export default App
    • Faker With Params
    import React, { Component } from 'react'
    import { Faker } from 'react-fakers'
    
    class App extends Component {
      constructor(props) {
        super(props)
        this.state = {
          loading: false,
          data: []
        }
      }
    
      onSuccess = (res) => {
        this.setState({
          loading: true,
          data: res
        })
      }
    
      onError = (error) => {
        if (error) {
          alert(error.message)
        }
      }
    
      render() {
        return (
          <>
            <Faker
              success={this.onSuccess}
              error={this.onError}
              type='addresses'
              params={{ addresses: { quantity: 5 } }}
            />
    
            {!this.state.loading && <h4>Loading....</h4>}
            <ul>
              {this.state.loading &&
                this.state.data.map((val, id) => (
                  <li key={val.uuid}>
                    {val.street} - {val.streetName} - {val.zipcode}
                  </li>
                ))}
            </ul>
          </>
        )
      }
    }
    
    export default App
    • JsonPlaceHolder
    import React, { Component } from 'react'
    import { JsonPlaceHolder } from 'react-fakers'
    
    class App extends Component {
      constructor(props) {
        super(props)
        this.state = {
          loading: false,
          data: []
        }
      }
    
      onSuccess = (res) => {
        this.setState({
          loading: true,
          data: res
        })
      }
    
      onError = (error) => {
        if (error) {
          alert(error.message)
        }
      }
    
      render() {
        return (
          <>
            <JsonPlaceHolder success={this.onSuccess} error={this.onError} />
    
            {!this.state.loading && <h4>Loading....</h4>}
            <ul>
              {this.state.loading &&
                this.state.data.map((val, id) => (
                  <li key={id}>
                    {val.name} - {val.email}
                  </li>
                ))}
            </ul> 
          </>
        )
      }
    }
    
    export default App
    • JsonPlaceHolder With Params
    import React, { Component } from 'react'
    import { JsonPlaceHolder } from 'react-fakers'
    
    class App extends Component {
      constructor(props) {
        super(props)
        this.state = {
          loading: false,
          data: []
        }
      }
    
      onSuccess = (res) => {
        this.setState({
          loading: true,
          data: res
        })
      }
    
      onError = (error) => {
        if (error) {
          alert(error.message)
        }
      }
    
      render() {
        return (
          <>
            <JsonPlaceHolder
              success={this.onSuccess}
              error={this.onError}
              type='posts'
              params = {{ posts: { userId: 1 } }},
              options={{ limit: 3 }}
            />
    
            {!this.state.loading && <h4>Loading....</h4>}
            <ul>
              {this.state.loading &&
                this.state.data.map((val, id) => (
                  <li key={val.uuid}>
                    {val.id} - {val.title}
                  </li>
                ))}
            </ul>
          </>
        )
      }
    }
    
    export default App

API REFERENCE

  • HOOKS
NamePropertyType DataOptional/RequiredDefault ValueDescription
useFakertypestringoptionalusersTo display dummy data from the Faker API
paramsobjectoptional{ }
useJsonPlaceHoldertypestringoptionalusersTo display dummy data from the Json Place Holder API
paramsobjectoptional{ }
optionsobjectoptional{ limit: 0 }
filtersobjectoptional{ }
useDummytypeobjectoptionaluserTo display dummy data from the Dummy API
apiKeystringoptional5faa1fab5317ae96860c0be3
paramsobjectoptional{ }
optionsobjectoptional{ limit: 0 }
filtersobjectoptional{ }
useUIFacesapiKeystringoptional43651248-182440F6-8653E4E2-5438FCB2To display dummy data from the UI Faces API
paramsobjectoptional{ limit: 10 }
useStarWarstypestringoptionalpeopleTo display dummy data from the Star Wars API
paramsobjectoptional{ }
optionsobjectoptional{ limit: 0 }
filtersobjectoptional{ }
  • COMPONENTS
NamePropertyType DataOptional/RequiredDefault ValueDescription
FakersuccessfunctionrequiredTo display dummy data from the Faker API
errorfunctionoptional
typestringoptionalusers
paramsobjectoptional
JsonPlaceHoldersuccessfunctionrequiredTo display dummy data from the Json Place Holder API
errorfunctionoptional
typestringoptionalusers
optionsobjectoptional{ limit: 0 }
filtersobjectoptional{ }
DummysuccessfunctionrequiredTo display dummy data from the Dummy API
errorfunctionoptional
apiKeystringoptional5faa1fab5317ae96860c0be3
paramsobjectoptional{ }
optionsobjectoptional{ limit: 0 }
filtersobjectoptional{ }
UIFacessuccessfunctionrequiredTo display dummy data from the UI Faces API
errorfunctionoptional
apiKeystringoptional43651248-182440F6-8653E4E2-5438FCB2
paramsobjectoptional{ limit: 10 }

API STATUS

API NameAPI KeyCall Per/DayCall Per/Month
FakerNoUnlimitedUnlimited
Json Place HolderNoUnlimitedUnlimited
Dummy APIYes500Undefined
UI FacesYes500Undefined
Star WarsNoUnlimitedUnlimited

API LIST

API NameStatusDocumentation
FakerReadyClick Here
Json Place HolderReadyClick Here
Dummy APIReadyClick Here
UI FacesReadyClick Here
PokemonComing SoonClick Here
Star WarsReadyClick Here
MarvelComing SoonClick Here
Harry PotterComing SoonClick Here
IMDBComing SoonClick Here
The CatComing SoonClick Here
AnimeComing SoonClick Here
Ricky And MortyComing SoonClick Here
UnsplashComing SoonClick Here
Listen NotesComing SoonClick Here

TRANSLATION

NOTES

  • For Provider that uses API KEY if you have a limit, please visit the API provider service, to get your own API KEY
  • For more information on the API available, you can visit the official documentation of each Provider
  • To find out more about using this tool, you can open the app-dev/src/examples in this repository

CONTRIBUTING

Want to make React Fakers more perfect ? Let's contribute and follow the contribution guide.

BUGS

For information on bugs related to package libraries, please visit here

AUTHOR

LICENSE