|
| 1 | +**React18 Loaders** |
| 2 | + |
| 3 | +*** |
| 4 | + |
| 5 | +# React18 Loaders <img src="https://raw.githubusercontent.com/mayank1513/mayank1513/main/popper.png" style="height: 40px"/> |
| 6 | + |
| 7 | +[](https://github.com/react18-tools/turborepo-template/actions/workflows/test.yml) [](https://codeclimate.com/github/react18-tools/turborepo-template/maintainability) [](https://codecov.io/gh/react18-tools/turborepo-template) [](https://www.npmjs.com/package/react18-loaders) [](https://www.npmjs.com/package/react18-loaders)  [](https://gitpod.io/from-referrer/) |
| 8 | + |
| 9 | +React18 Loaders is a comprehensive library designed to unlock the full potential of React 18 server components. It provides customizable loading animation components and a fullscreen loader container, seamlessly integrating with React and Next.js. |
| 10 | + |
| 11 | +✅ Fully Treeshakable (import from `react18-loaders/client/loader-container`) |
| 12 | + |
| 13 | +✅ Fully TypeScript Supported |
| 14 | + |
| 15 | +✅ Leverages the power of React 18 Server components |
| 16 | + |
| 17 | +✅ Compatible with all React 18 build systems/tools/frameworks |
| 18 | + |
| 19 | +✅ Documented with [Typedoc](https://react18-tools.github.io/turborepo-template) ([Docs](https://react18-tools.github.io/turborepo-template)) |
| 20 | + |
| 21 | +✅ Examples for Next.js, and Vite |
| 22 | + |
| 23 | +> <img src="https://raw.githubusercontent.com/mayank1513/mayank1513/main/popper.png" style="height: 20px"/> Star [this repository](https://github.com/react18-tools/turborepo-template) and share it with your friends. |
| 24 | +
|
| 25 | +## Getting Started |
| 26 | + |
| 27 | +### Installation |
| 28 | + |
| 29 | +```bash |
| 30 | +pnpm add react18-loaders |
| 31 | +``` |
| 32 | + |
| 33 | +**_or_** |
| 34 | + |
| 35 | +```bash |
| 36 | +npm install react18-loaders |
| 37 | +``` |
| 38 | + |
| 39 | +**_or_** |
| 40 | + |
| 41 | +```bash |
| 42 | +yarn add react18-loaders |
| 43 | +``` |
| 44 | + |
| 45 | +## Want Lite Version? [](https://www.npmjs.com/package/react18-loaders-lite) [](https://www.npmjs.com/package/react18-loaders-lite) [](https://www.npmjs.com/package/react18-loaders-lite) |
| 46 | + |
| 47 | +```bash |
| 48 | +pnpm add react18-loaders-lite |
| 49 | +``` |
| 50 | + |
| 51 | +**or** |
| 52 | + |
| 53 | +```bash |
| 54 | +npm install react18-loaders-lite |
| 55 | +``` |
| 56 | + |
| 57 | +**or** |
| 58 | + |
| 59 | +```bash |
| 60 | +yarn add react18-loaders-lite |
| 61 | +``` |
| 62 | + |
| 63 | +> You need `r18gs` as a peer-dependency |
| 64 | +
|
| 65 | +### Import Styles |
| 66 | + |
| 67 | +You can import styles globally or within specific components. |
| 68 | + |
| 69 | +```css |
| 70 | +/* globals.css */ |
| 71 | +@import "react18-loaders/dist"; |
| 72 | +``` |
| 73 | + |
| 74 | +```tsx |
| 75 | +// layout.tsx |
| 76 | +import "react18-loaders/dist/index.css"; |
| 77 | +``` |
| 78 | + |
| 79 | +For selective imports: |
| 80 | + |
| 81 | +```css |
| 82 | +/* globals.css */ |
| 83 | +@import "react18-loaders/dist/client"; /** required if you are using LoaderContainer */ |
| 84 | +@import "react18-loaders/dist/server/bars/bars1"; |
| 85 | +``` |
| 86 | + |
| 87 | +### Usage |
| 88 | + |
| 89 | +Using loaders is straightforward. |
| 90 | + |
| 91 | +```tsx |
| 92 | +import { Bars1 } from "react18-loaders/dist/server/bars/bars1"; |
| 93 | + |
| 94 | +export default function MyComponent() { |
| 95 | + return someCondition ? <Bars1 /> : <>Something else...</>; |
| 96 | +} |
| 97 | +``` |
| 98 | + |
| 99 | +For detailed API and options, refer to [the API documentation](https://react18-tools.github.io/turborepo-template). |
| 100 | + |
| 101 | +**Using LoaderContainer** |
| 102 | + |
| 103 | +`LoaderContainer` is a fullscreen component. You can add this component directly in your layout and then use `useLoader` hook to toggle its visibility. |
| 104 | + |
| 105 | +```tsx |
| 106 | +// layout.tsx |
| 107 | +<LoaderContainer /> |
| 108 | + ... |
| 109 | +``` |
| 110 | + |
| 111 | +```tsx |
| 112 | +// some other page or component |
| 113 | +import { useLoader } from "react18-loaders/dist/hooks"; |
| 114 | + |
| 115 | +export default MyComponent() { |
| 116 | + const { setLoading } = useLoader(); |
| 117 | + useCallback(()=>{ |
| 118 | + setLoading(true); |
| 119 | + ...do some work |
| 120 | + setLoading(false); |
| 121 | + }, []) |
| 122 | + ... |
| 123 | +} |
| 124 | +``` |
| 125 | + |
| 126 | +## License |
| 127 | + |
| 128 | +This library is licensed under the MPL-2.0 open-source license. |
| 129 | + |
| 130 | +> This package also serves as an example demonstrating how to build and publish a `React.js` library compatible with React Server Components. |
| 131 | + |
| 132 | +> <img src="https://raw.githubusercontent.com/mayank1513/mayank1513/main/popper.png" style="height: 20px"/> Please enroll in [our courses](https://mayank-chaudhari.vercel.app/courses) or [sponsor](https://github.com/sponsors/mayank1513) our work. |
| 133 | + |
| 134 | +<hr /> |
| 135 | + |
| 136 | +<p align="center" style="text-align:center">with 💖 by <a href="https://mayank-chaudhari.vercel.app" target="_blank">Mayank Kumar Chaudhari</a></p> |
0 commit comments