npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-laravel-pagin

v1.2.0

Published

#Note Fixed our femous error of `null of useState` Enjoy This is a simple tool which enables people who works with react with backend of laravel api and wanted to consume the laravel pagination results.

Downloads

25

Readme

Introduction React Laravel Pagin

#Note Fixed our femous error of null of useState Enjoy This is a simple tool which enables people who works with react with backend of laravel api and wanted to consume the laravel pagination results.

Its makes easy flexible and friendly, you just focus on looks of your UI and not the mechanics of laravel pagination results on your react app

Installing

on your root directory npm install react-laravel-pagin

and you're all set to start using your lovely tool

Using react-laravel-pagin

inside the page you need paginator import {ReactLaravelPagin} from 'react-laravel-pagin'

and use your component as

 <ReactLaravelPagin

    baseLink='http://localhost:8000/api/users'

    headers={{
         ...
     //You're headers,
     Access : `Bearer ${token}`,
     X-Custom-Header : `Some crazy header`,

    }}

    setIsLoading={setIsLoading}

    dataPicker={(data) => data.trips}

    setDataList={setTrips}

    customDots={() => <h3 className="d-inline-block">...</h3>}

    customPrev={(props) => <span {...props}>prev</span>}

    customNext={(props) => <span {...props}>next</span>}

    linkStyle={(active, prev, next) =>
      `btn ${active ? "btn-success" : "btn-default"} mx-1`
    }

  />

if you've putted everything right and still you're getting some error or unexpected results, email me on [email protected] so we can collaborate to see where you've stuck with our library

Props definition

baseLink is a link to laravel-api which gives paginated results example http://localhost:8000/api/users just the link itself and no more parameters to it

headers is object of http headers since sometimes you need authorization to be able to access some end points if there is more header just comma separate them on the headers object :)

setIsLoading in here just pass in a function which receives either true/false it could be from hooks from which you can trigger loading... state so users gets feedback

as const [isLoading, setIsLoading] = useState(false) so instead of triggering setIsLoading(true) manually

you just pass setIsLoading to the ReactLaravelPagin and it'll handle the rest for you as below

 <ReactLaravelPagin
...
setIsLoading = {setIsLoading}

>

dataPicker receives a callback function which will receive a response from the server this response will be inside object called data

so on laravel api we have custom of giving response as below

return response()->json(([ 'status' => 200, 'users' => $users ]));

so on dataPicker function (data) => data.users actually states that the data you really want to work with is inside users property

setDataList This is a function which receives the data in this case could be users to displayed on the page, not pagination links, really data of users, it could be customers or mybe products etc, for react best practice you can pass i a hook as below

const [users, setUsers] = useState([])

observe how the setUsers function is injected into the component and so when we have those users we can actually access them on users variable :)

customDots actually passes in a component which will replace the default ... dots on long pagination

customPrev passes a component which will replace default prev component

Note:

Make sure you pass in the props on the customPrev and customNext since they hold other functionalities

linkStyle Receives function which you can use to customize the css looks of the component to blend in for your site this function receives three parameters, active => if the link is active boolean, prev => true if this link is prev link, next => true if the link is next link, inside this function returns the style which will be applied the respective pagination link

Note:

You're adviced to create you're component ready on customPrev and customNext in the case of styling and not depend on linkStyle

For react-laravel-pagin to work here is short summary

        const [isLoading, setIsLoading] = useState(false);
        const [dataList, setDataList] = useState([]);
        //Make sure you pass props for customPrev and customNext as shown on example
        //Instead of <span> tags you can use whatever your tags are but make sure to pass props in as shown

         ....

        <ReactLaravelPagin

        baseLink="http://localhost:8000/api/users"

        headers={{Authorization : "Bearer " + 'you're token'}}

        setIsLoading={setIsLoading}

        dataPicker={(data) => data.users}

        setDataList={setUsers}

        customDots={() => <h3 className="d-inline-block">...</h3>}

        customPrev={(props) => <span {...props}>prev</span>}

        customNext={(props) => <span {...props}>next</span>}

        linkStyle={(active, prev, next) => `btn ${active ? "btn-success" : "btn-default"} mx-1` }

/>`