Convert Figma logo to code with AI

craig1123 logoreact-recipes

👩‍đŸŗ A list of React Hooks utility library containing popular customized hooks

1,020
65
1,020
13

Top Related Projects

33,863

Build forms in React, without the tears 😭

41,619

🤖 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

46,119

đŸģ Bear necessities for state management in React

41,619

🤖 Powerful asynchronous state management, server-state utilities and data fetching for the web. TS/JS, React Query, Solid Query, Svelte Query and Vue Query.

30,209

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

  1. 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>
  );
}
  1. 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>
    </>
  );
}
  1. 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

33,863

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>
41,619

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

46,119

đŸģ 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.

41,619

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

30,209

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 Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

react-recipes-logo

React Recipes

A React Hooks utility library containing popular customized hooks

What's your favorite dish?

Build Status

npm i react-recipes --save
yarn add react-recipes

ðŸÂĨ˜ Recipes Documentation

NameReturnsArguments
Ã°ÂŸÂÂĄ useAdjustColorcolor(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]-
🍜 useDebouncedebouncedValue(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: [])
🍐 useIsClientisClient-
ðŸÂĨ§ useKeyPresskeyPressed(targetKey)
Ã°ÂŸÂÂą useLocalStorage[storedValue, setValue](key, initialValue)
📍 useLocation{ push, replace, pathname, search }-
🍋 useLockBodyScroll--
🍉 useMediavalue(queries, values, defaultValue)
ðŸÂĨ­ useMultiKeyPresskeysPressed(targetKey)
🔔 useNotificationfireNotify(title, options)
ðŸÂĨ‘ useOnClickOutside-(ref, callback)
ðŸÂĨ’ useOnlineStatusonlineStatus-
ðŸÂŋ usePreviousprevious(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 })
🍏 useThrottlethrottledValue(value, ms: 250)
Ã°ÂŸÂÂˇ useWhyDidYouUpdate-(name, props)
ðŸÂĨ– useWindowScroll{ x, y }-
ðŸÂĨÂŽ useWindowSize{ height, width }(initialWidth, initialHeight)
ðŸÂĨ useWorkerworker instance(scriptPath, workerOptions, attributes)

NPM DownloadsLast 30 Days