react-recipes
đŠâđŗ A list of React Hooks utility library containing popular customized hooks
Top Related Projects
Build forms in React, without the tears đ
đ¤ Powerful asynchronous state management, server-state utilities and data fetching for the web. TS/JS, React Query, Solid Query, Svelte Query and Vue Query.
The official, opinionated, batteries-included toolset for efficient Redux development
đģ Bear necessities for state management in React
đ¤ Powerful asynchronous state management, server-state utilities and data fetching for the web. TS/JS, React Query, Solid Query, Svelte Query and Vue Query.
React Hooks for Data Fetching
Quick Overview
React Recipes is a collection of lightweight, customizable React components and hooks designed to simplify common UI tasks. It provides a set of reusable building blocks for React applications, focusing on performance and ease of use.
Pros
- Lightweight and modular, allowing developers to import only the components they need
- Highly customizable with extensive prop options for each component
- Includes both components and hooks, offering flexibility in implementation
- Well-documented with clear examples and TypeScript support
Cons
- Limited styling options out of the box, requiring additional CSS for advanced customization
- Some components may lack advanced features found in more comprehensive UI libraries
- Relatively small community compared to larger React component libraries
- May require additional setup for certain components to work with server-side rendering
Code Examples
- Using the useClipboard hook:
import { useClipboard } from 'react-recipes';
function CopyButton({ text }) {
const [isCopied, setCopied] = useClipboard(text, {
successDuration: 2000,
});
return (
<button onClick={setCopied}>
{isCopied ? 'Copied!' : 'Copy to clipboard'}
</button>
);
}
- Implementing a modal using the Modal component:
import { Modal } from 'react-recipes';
function App() {
const [isOpen, setIsOpen] = useState(false);
return (
<>
<button onClick={() => setIsOpen(true)}>Open Modal</button>
<Modal isOpen={isOpen} onClose={() => setIsOpen(false)}>
<h2>Modal Content</h2>
<p>This is the modal body.</p>
</Modal>
</>
);
}
- Using the Tooltip component:
import { Tooltip } from 'react-recipes';
function InfoIcon() {
return (
<Tooltip content="This is additional information" placement="top">
<span>âšī¸</span>
</Tooltip>
);
}
Getting Started
To use React Recipes in your project, first install it via npm or yarn:
npm install react-recipes
# or
yarn add react-recipes
Then, import and use the desired components or hooks in your React application:
import React from 'react';
import { Button, useToggle } from 'react-recipes';
function ToggleButton() {
const [isOn, toggle] = useToggle(false);
return (
<Button onClick={toggle}>
{isOn ? 'Turn Off' : 'Turn On'}
</Button>
);
}
This example demonstrates how to use the Button component and the useToggle hook from the library.
Competitor Comparisons
Build forms in React, without the tears đ
Pros of Formik
- More comprehensive form management solution with built-in validation, error handling, and form submission
- Larger community and ecosystem, with extensive documentation and third-party integrations
- Better performance optimization for complex forms with many fields
Cons of Formik
- Steeper learning curve due to its more extensive API and concepts
- Potentially overkill for simple forms or projects with minimal form requirements
- Larger bundle size compared to lightweight alternatives
Code Comparison
Formik:
import { Formik, Form, Field } from 'formik';
<Formik
initialValues={{ email: '', password: '' }}
onSubmit={(values) => console.log(values)}
>
<Form>
<Field name="email" type="email" />
<Field name="password" type="password" />
<button type="submit">Submit</button>
</Form>
</Formik>
React-recipes:
import { useForm } from 'react-recipes';
const { values, handleChange, handleSubmit } = useForm({
email: '',
password: '',
});
<form onSubmit={handleSubmit}>
<input name="email" type="email" onChange={handleChange} value={values.email} />
<input name="password" type="password" onChange={handleChange} value={values.password} />
<button type="submit">Submit</button>
</form>
đ¤ Powerful asynchronous state management, server-state utilities and data fetching for the web. TS/JS, React Query, Solid Query, Svelte Query and Vue Query.
Pros of Query
- More comprehensive data fetching and state management solution
- Robust caching and synchronization features
- Active development and large community support
Cons of Query
- Steeper learning curve due to more complex API
- Potentially overkill for simple applications
- Requires additional setup and configuration
Code Comparison
Query:
import { useQuery } from 'react-query';
function Example() {
const { isLoading, error, data } = useQuery('todos', fetchTodos);
// ... rest of the component
}
React Recipes:
import { useAsync } from 'react-recipes';
function Example() {
const { loading, error, value } = useAsync(fetchTodos);
// ... rest of the component
}
Summary
Query is a more powerful and feature-rich solution for data fetching and state management, offering advanced caching and synchronization capabilities. It's well-suited for complex applications with demanding data requirements. However, it comes with a steeper learning curve and may be excessive for simpler projects.
React Recipes provides a collection of lightweight hooks, including a basic async data fetching solution. It's easier to pick up and integrate into smaller projects but lacks the advanced features and ecosystem support of Query.
The choice between the two depends on the project's complexity, data management needs, and the development team's familiarity with each library.
The official, opinionated, batteries-included toolset for efficient Redux development
Pros of Redux Toolkit
- More comprehensive state management solution
- Includes utilities for common Redux use cases (e.g., createSlice, createAsyncThunk)
- Better integration with modern Redux best practices
Cons of Redux Toolkit
- Steeper learning curve for beginners
- More opinionated approach, which may not suit all project needs
- Larger bundle size due to additional features
Code Comparison
Redux Toolkit:
import { createSlice } from '@reduxjs/toolkit'
const counterSlice = createSlice({
name: 'counter',
initialState: 0,
reducers: {
increment: state => state + 1,
},
})
React Recipes:
import { useReducer } from 'react'
const [count, dispatch] = useReducer((state, action) => {
if (action === 'increment') return state + 1
return state
}, 0)
Summary
Redux Toolkit offers a more robust state management solution with built-in utilities and best practices, while React Recipes provides simpler, more lightweight custom hooks for specific use cases. Redux Toolkit is better suited for larger applications with complex state management needs, whereas React Recipes may be more appropriate for smaller projects or those requiring specific React-based solutions.
đģ Bear necessities for state management in React
Pros of zustand
- Lightweight and minimalistic state management solution
- Supports middleware and devtools for enhanced functionality
- Easy integration with React hooks
Cons of zustand
- Less comprehensive than react-recipes for general React patterns
- May require additional setup for complex state management scenarios
- Limited built-in utilities compared to react-recipes
Code Comparison
zustand:
import create from 'zustand'
const useStore = create(set => ({
count: 0,
increment: () => set(state => ({ count: state.count + 1 })),
}))
react-recipes:
import { useReducer } from 'react'
const [state, dispatch] = useReducer(reducer, initialState)
dispatch({ type: 'INCREMENT' })
Summary
zustand focuses on lightweight state management, offering a simple API and easy integration with React hooks. It's ideal for projects requiring efficient state handling without the complexity of larger state management libraries.
react-recipes provides a broader collection of React patterns and utilities, making it more suitable for developers seeking a comprehensive toolkit for various React development scenarios.
Choose zustand for streamlined state management in smaller to medium-sized projects, while react-recipes might be preferable for larger applications requiring diverse React patterns and utilities.
đ¤ Powerful asynchronous state management, server-state utilities and data fetching for the web. TS/JS, React Query, Solid Query, Svelte Query and Vue Query.
Pros of Query
- More comprehensive data fetching and state management solution
- Robust caching and synchronization features
- Active development and large community support
Cons of Query
- Steeper learning curve due to more complex API
- Potentially overkill for simple applications
- Requires additional setup and configuration
Code Comparison
Query:
import { useQuery } from 'react-query';
function Example() {
const { isLoading, error, data } = useQuery('todos', fetchTodos);
// ... rest of the component
}
React Recipes:
import { useAsync } from 'react-recipes';
function Example() {
const { loading, error, value } = useAsync(fetchTodos);
// ... rest of the component
}
Summary
Query is a more powerful and feature-rich solution for data fetching and state management, offering advanced caching and synchronization capabilities. It's well-suited for complex applications with demanding data requirements. However, it comes with a steeper learning curve and may be excessive for simpler projects.
React Recipes provides a collection of lightweight hooks, including a basic async data fetching solution. It's easier to pick up and integrate into smaller projects but lacks the advanced features and ecosystem support of Query.
The choice between the two depends on the project's complexity, data management needs, and the development team's familiarity with each library.
React Hooks for Data Fetching
Pros of SWR
- More comprehensive data fetching solution with built-in caching, revalidation, and error handling
- Supports real-time data updates and optimistic UI
- Larger community and more frequent updates
Cons of SWR
- Steeper learning curve due to more advanced features
- May be overkill for simpler projects that don't require advanced data management
- Slightly larger bundle size
Code Comparison
SWR:
import useSWR from 'swr'
function Profile() {
const { data, error } = useSWR('/api/user', fetcher)
if (error) return <div>Failed to load</div>
if (!data) return <div>Loading...</div>
return <div>Hello {data.name}!</div>
}
React-recipes:
import { useAsync } from 'react-recipes'
function Profile() {
const { loading, error, value } = useAsync(() => fetchUser())
if (error) return <div>Failed to load</div>
if (loading) return <div>Loading...</div>
return <div>Hello {value.name}!</div>
}
Both libraries provide hooks for data fetching, but SWR offers more built-in features for managing data states and caching. React-recipes provides a simpler API that may be easier to understand for beginners or smaller projects. SWR's approach is more declarative, while React-recipes relies on a callback function for data fetching.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
React Recipes
A React Hooks utility library containing popular customized hooks
What's your favorite dish?
npm i react-recipes --save
yarn add react-recipes
ðÂÂĨ Recipes Documentation
Name | Returns | Arguments |
---|---|---|
ðÂÂÂĄ useAdjustColor | color | (percentage, color1, color2: null, linearBlend: false) |
ðÂÂĨ useArray | { value, setValue, removeById, removeIndex, clear } | (initialValue) |
ð useAsync | { error, execute, pending, value } | (asyncFunction, immediate: true) |
ðÂÂÂĒ useCookie | [cookieValue, updateCookie, deleteCookie] | (cookieName, initialValue) |
ðÂÂĨ useCopyClipboard | [isCopied, setIsCopied] | (duration: 2000) |
ðŠ useDarkMode | [enabled, setEnabledState] | - |
ð useDebounce | debouncedValue | (value, delay) |
ðÂÂĨÂĄ useDimensions | [ref, dimensions, node] | (liveMeasure: true, delay: 250, initialDimensions: {}, effectDependencies: []) |
ðÂÂÂŗ useEventListener | - | (eventName, handle, element: window) |
ðÂÂÂŽ useFullScreen | { fullScreen, open, close, toggle } | (element: document.documentElement) |
ð¯ useGeolocation | { latitude, longitude, timestamp, accuracy, error } | (watch: false, settings: {enableHighAccuracy: false, timeout: Infinity, maximumAge: 0}) |
ð useHover | [callbackRef, value] | - |
ðÂÂÂĻ useInterval | - | (callback, delay, runOnLoad: false, effectDependencies: []) |
ð useIsClient | isClient | - |
ðÂÂĨ§ useKeyPress | keyPressed | (targetKey) |
ðÂÂÂą useLocalStorage | [storedValue, setValue] | (key, initialValue) |
ð useLocation | { push, replace, pathname, search } | - |
ð useLockBodyScroll | - | - |
ð useMedia | value | (queries, values, defaultValue) |
ðÂÂĨ useMultiKeyPress | keysPressed | (targetKey) |
ð useNotification | fireNotify | (title, options) |
ðÂÂĨ useOnClickOutside | - | (ref, callback) |
ðÂÂĨ useOnlineStatus | onlineStatus | - |
ðÂÂÂŋ usePrevious | previous | (value) |
ð¨ usePrint | { ref, handlePrint } | (style = {}) |
:question: useQueryParams | { getParams, setParams } | - |
ðÂÂÂŖ useScript | [loaded, error] | (src) |
ð useSpeechRecognition | { supported, listen, listening, stop } | ({ onEnd, onResult, onError }) |
ð useSpeechSynthesis | { supported, speak, speaking, cancel, voices, pause, resume } | ({ onEnd, onResult, onError, onBoundary, onPause, onResume }) |
ð useThrottle | throttledValue | (value, ms: 250) |
ð¡ useWhyDidYouUpdate | - | (name, props) |
ðÂÂĨ useWindowScroll | { x, y } | - |
ðÂÂĨÂŽ useWindowSize | { height, width } | (initialWidth, initialHeight) |
ðÂÂĨ useWorker | worker instance | (scriptPath, workerOptions, attributes) |
Top Related Projects
Build forms in React, without the tears đ
đ¤ Powerful asynchronous state management, server-state utilities and data fetching for the web. TS/JS, React Query, Solid Query, Svelte Query and Vue Query.
The official, opinionated, batteries-included toolset for efficient Redux development
đģ Bear necessities for state management in React
đ¤ Powerful asynchronous state management, server-state utilities and data fetching for the web. TS/JS, React Query, Solid Query, Svelte Query and Vue Query.
React Hooks for Data Fetching
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot