What will happen if I have multiple nested SWRConfig components with different options selected?

I am currently utilizing SWRConfig to implement a global fetcher, but I also have the requirement to override this fetcher in certain components. In such a scenario, would the options specified at a higher level of SWRConfig be applied?

<SWRConfig
    value={{
      fetcher: (resource, init) =>
        fetch(resource, init).then((res) => res.json()),
    }}
  >
       ...
         <SWRConfig
             value={{
               fetcher: customFetch
            }}
          >

Answer №1

If you have nested SWRConfig setups, the configurations will be combined. In simple terms, if you use useSWR within the second SWRConfig, it will utilize the fetcher specified there (customFetch).

Another option is to set the fetcher directly on the useSWR call to override the global fetcher whenever necessary.

useSWR('my-key', customFetch)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"The Material UI date picker is encountering an issue with the error prop, which is being evaluated

I have developed a date picker that utilizes the Jalali calendar. While attempting to pass error checking using the error prop in the following code: <LocalizationProvider dateAdapter={AdapterJalali}> <MobileDatePicker label={lab ...

When modifying the state of an array within a component, certain values may be overwritten and lost in the process

Currently, I'm faced with the challenge of ensuring that a component displays a loading screen until all images have completed loading. This is necessary because there are approximately 25 images that must finish loading before the page can be display ...

What causes the webpage to reset its scroll position when a component rerenders?

In the process of creating my personal blog with Next.js, I retrieve posts from my API using a page query for pagination. Then, I iterate through the items in this manner: let content = ( <ul> {props.posts.map((post) => { return &l ...

"Padding has not been recognized as a valid input value

I'm struggling with getting padding to be accepted by the browser when I style a card using Material-UI. const useStyles = makeStyles((theme) => ({ cardGrid: { padding: '20px auto' }, })) Unfortunately, the browser is not recogni ...

Is it possible for JavaScript/React to observe the movement of elements on the webpage?

I'm searching for a solution to detect if an element moves on the screen. Currently, I have an absolute positioned div (acting as a download overlay) that appears when a document is clicked on my website. However, I want it to disappear whenever the d ...

Whenever I attempt to make changes to the React state, it always ends up getting reset

Currently, I am attempting to utilize Listbox provided by Headless UI in order to create a select dropdown menu for filtering purposes within my application. However, the issue I have encountered is that whenever I update my "selectedMake" state, it revert ...

Encountering a problem with the navigation bar in the latest version of Next.js, version 13

"use client" import {Navbar, Button, Link, Text} from "@nextui-org/react"; import {styled} from "@nextui-org/react" const Box = styled("div", { boxSizing: "border-box", }); const AcmeLogo = () => ( ...

React Material UI ALL CAPS EDITION

Can the theme description be styled to display all text in uppercase using textTransform? This includes static text, inputs, and any fetched data. ...

How can I pass my cookie token in a Next.js server-side component request?

My Next.js version is 14.1.0 and I am currently using the App router. async function Page() { const dataPromise: Promise<any> = getData(); const data = await dataPromise; console.log('data: ', data); return ( .... ); } The ge ...

Upcoming verification with JSON Web Token

I am looking to incorporate JWT auth into my Next app. Currently, I have mapped out the flow as such: User enters email and password to log in Server responds with status 200 and a jwt access token in httpOnly cookies My main dilemma lies in deciding on ...

In ReactJS, removing the value from Material-UI TextField displays the previously entered text

I have implemented a SearchBar feature in my ReactJS application. Below is the code snippet for the SearchBar: import React, { useState, useImperativeHandle, forwardRef, useEffect } from 'react'; import { makeStyles } from '@material-ui/core ...

Tips for sending custom props to a dynamic page in Next.js

I have created a component called Card.js which is responsible for linking to dynamic pages when a card is clicked. My goal is to pass a value, such as 'category', to the dynamic page [id].js so that I can implement additional logic there. Card. ...

A guide on how to add an item to an array in React Native

Recently, I've started working with React and exploring a floating point feature that allows users to select different options. Depending on the selection made, specific information is added to an array, which is then used to populate a card displayed ...

Encountering a NextJS Error while trying to render a page, following a recent post

Recently, I encountered an issue with my Next.js application that is connected to my NodeJS API. I have a form on one of the pages that sends POST requests to the backend API. However, upon submitting the form and being redirected to another page, pressin ...

Error: Incorrect Path for Dynamic Import

Recently, I've been trying to dynamically load locale files based on the locale code provided by Next.js. Unfortunately, every time I attempt a dynamic import, an error surfaces and it seems like the import path is incorrect: Unable to load translatio ...

What is the best way to send props from a child component to its parent in a React

I'm a beginner in React and I'm attempting to develop a "CV-Generator" similar to the one shown here. In this application, whenever a user inputs data in any of the input fields, it is automatically displayed in the render preview on the right si ...

Enhancing the appearance of an image upon hovering in ReactJS: A step-by-step guide

My issue arises from my desire to border an image and display a Card with information upon hovering, but the problem is that this style is being applied to all images rather than just the one being hovered over. After pulling data from a movie API, I stor ...

What is the best way to present JSON data retrieved from an API on different pages using Next.js?

I am currently working on two pages that are connected: one is an API page called secured.js (where user session data is processed) and the other is a normal page also named secured.js (which displays the processed content from the API page). This is the ...

The NextUI Table example encounters an issue with a TypeError, specifically stating that it is unable to read properties of undefined, specifically referring to the

Seeking assistance with a React error as I am relatively new to the framework. While I have some basic knowledge of client and server side rendering, this particular issue has stumped me. Following this example: Use Case Example When creating a table, yo ...

Material UI autocomplete with multiple selection

I am attempting to maintain state for a multi-select Autocomplete by using an array of strings. However, I also need an array of objects to store the relationship between the strings representing state on the backend and the labels for display. In this sce ...