How can I resolve the issue of React not identifying the prop on a DOM element?

Currently, I am learning React and facing an issue with a warning message: "react-dom.development.js:86 Warning: React does not recognize the isSelected prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase isselected instead. If you accidentally passed it from a parent component, remove it from the DOM element."

This warning only pops up occasionally when I render my Survey component, sometimes requiring me to reload the page multiple times before it shows.

In my Survey component, I have two clickable buttons labeled "yes" and "no" for answering questions. The goal is to add a box-shadow CSS property to the selected answer, which I achieved using CSS-in-JS with a conditional statement. While this works correctly, the warning persists...

Below is the code snippet of my Survey element:

// various imports

const SurveyContainer = styled.div`...
`;

const QuestionTitle = styled.h2`...
`;

const QuestionContent = styled.span`...
`;

const LinkWrapper = styled.div`...
`;

const ReplyBox = styled.button`
    // other CSS properties
    box-shadow: ${(props) =>
        props.isSelected ? `0px 0px 0px 2px ${colors.primary} inset` : "none"};
    &:first-child {
        margin-right: 15px;
    }
    &:last-of-type {
        margin-left: 15px;
    }
`;

const ReplyWrapper = styled.div`
    // CSS properties
`;

function Survey() {
    const { questionNumber } = useParams();
    const questionNumberInt = parseInt(questionNumber);
    const prevQuestionNumber =
        questionNumberInt === 1 ? 1 : questionNumberInt - 1;
    const nextQuestionNumber = questionNumberInt + 1;
    const [surveyData, setSurveyData] = useState({});
    const [isDataLoading, setDataLoading] = useState(false);
    const { answers, saveAnswers } = useContext(SurveyContext);
    const [error, setError] = useState(false);

    function saveReply(answer) {
        saveAnswers({ [questionNumber]: answer });
    }

    useEffect(() => {
        async function fetchSurvey() {...
        }
        fetchSurvey();
    }, []);

    if (error) {...
    }

    return (
        <SurveyContainer>
            <QuestionTitle>Question {questionNumber}</QuestionTitle>
            {isDataLoading ? (
                <Loader />
            ) : (
                <QuestionContent>{surveyData[questionNumber]}</QuestionContent>
            )}
            <ReplyWrapper>
                <ReplyBox
                    onClick={() => saveReply(true)}
                    isSelected={answers[questionNumber] === true}
                >
                    Yes
                </ReplyBox>
                <ReplyBox
                    onClick={() => saveReply(false)}
                    isSelected={answers[questionNumber] === false}
                >
                    No
                </ReplyBox>
            </ReplyWrapper>
            <LinkWrapper>
                <Link to={`/survey/${prevQuestionNumber}`}>Previous</Link>
                {surveyData[questionNumberInt + 1] ? (
                    <Link to={`/survey/${nextQuestionNumber}`}>Next</Link>
                ) : (
                    <Link to="/results">Results</Link>
                )}
            </LinkWrapper>
        </SurveyContainer>
    );
}

export default Survey;

I need to find a way to use the prop for the CSS validation without triggering the error. Maybe I cannot write "isSelected={answers[questionNumber] === true}" in the "ReplyBox" because it's a button styled-component rather than another React component? However, I still require a button...

Is there any alternative to a prop that could provide the same outcome?

Answer №1

Within the "styles" section of the "FeedbackForm", make sure to include "props.$isChecked" and also add the dollar sign before "isChecked" in your final output.

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

Angular toolbar on the left side that hovers seamlessly

1 I am using Angular Material toolbar and trying to position a span inside the toolbar on the left side. I have attempted using CSS float left, but it is not working. Can anyone provide some assistance please? <mat-toolbar> <span>le ...

Incorporate Bootstrap styling into a layout featuring a row containing numerous input fields

I need some help with styling using bootstrap 5. I have set up a codepen for reference: https://codepen.io/korazy/pen/xxmWGOx Here are the issues I am facing: The input height changes to match the row height when text wraps. How can I keep the input at ...

Exploring the effective utilization of bootstrap's push and pull functionalities

I've been struggling to rearrange my bootstrap columns for mobile view, but my code just isn't cooperating. It's likely that I'm making a mistake somewhere. Here is the snippet of my code: <div class="container"> <div cla ...

What could be the reason for the absence of the 'www-authenticate' header when accessing the API through a React application?

When my React application calls a web api project that uses JWT for authentication with an expired token, the expected 401 response is received, but the 'www-authentication' header containing the message explaining the reason for the 401 is missi ...

Multer throws an error when uploading files due to an unexpected field issue

Hello, I am currently working on creating a file upload API using React and Express. To achieve this, I decided to use Muster. However, when I send an Axis request from the client, I encounter an error from the server. Error: MulterError: Unexpected fie ...

Creating dynamic rows for Firebase data in React BootstrapTable can be accomplished by dynamically rendering each row

Hey everyone, I'm currently working on a web app project where I am creating a table. Below is the code snippet for it: class Table1 extends Component { render() { return ( <div> <BootstrapTable data={this.props.data}> ...

Is it possible to trigger the onNewRequest property when the onBlur event is fired for AutoComplete in Material-UI?

Currently, I am utilizing Material-UI and making use of the onNewRequest property in the AutoComplete field. However, the onNewRequest only triggers when Enter is pressed or when a value is selected. I am interested in calling the onNewRequest even when ...

Unable to render dynamic ID in Next.js version 13.4.6 due to an issue

Currently diving into next-js! Previously, I utilized dynamic id rendering in my projects. However, encountering errors now with the current version (next js 13.4.6). Having trouble identifying the issue. Could it be due to not having a 'pages' f ...

The transitionend event fails to trigger if there is no active transition taking place

Take a look at this: http://jsfiddle.net/jqs4yy0p/ JS $('div').addClass('switch').on('transitionend', function(e){ alert('end'); }); CSS div { background-color: red; /*transition: background-colo ...

React's componentDidUpdate being triggered before prop change occurs

I am working with the CryptoHistoricGraph component in my app.js file. I have passed this.state.coinPrices as a prop for this element. import React from 'react'; import axios from 'axios'; import CryptoSelect from './components/cry ...

How to integrate the BackButton component into a React-admin application

I am looking to add a <BackButton /> feature in my use of react-admin. For instance, when viewing a show page for a resource, I want to be able to navigate back to the list page easily. Can someone provide me with guidance on how to achieve this? I ...

What is the reason behind LESS displaying arithmetic operations as text instead of performing them?

Whilst composing the subsequent operations @a: 2px @variable: @a + 5; .margin-style{ margin-left: @variable; } The code above compiles into .margin-style{ margin-left: 2px + 5; } Rather than margin-left:7px; What could be causing this issue? ...

Discovering unutilized node modules in your React project - A practical guide

Looking for a way to clean up unnecessary node modules and their dependencies from a project. I've done some research online and came across a few NPM packages that claim to achieve this, but none seem to meet my specific needs. Important: Node modu ...

Issue encountered in React Flow while working with Props type, during the conversion process of a Create-React app

I recently decided to convert a create-react app to a webpack app. The motivation behind this decision was that I had an existing project created with create-react and wanted to switch it over to webpack. To do this, I replaced all the source files in a we ...

The attempt to compress the code in the file from './node_modules/num2persian' using num2persian was unsuccessful

I have been using the num2persian library to convert numbers into Persian characters. However, whenever I run the command npm run build, I encounter the following error: An error occurred while trying to minimize the code in this file: ./node_modules/num ...

Can you please enlighten me on the significance of "m" in the context of MUI styles?

One of my MUI components has a unique property called sx. Can you explain what the value m:1 signifies in this context? sx={{ display: 'flex', flexWrap: 'wrap', '& > :not(style)': { m: 1, width: 128, h ...

Prevent clicks from passing through the transparent header-div onto bootstrap buttons

I have a webpage built with AngularJS and Bootstrap. It's currently in beta and available online in (German and): teacher.scool.cool simply click on "test anmelden" navigate to the next page using the menu This webpage features a fixed transparent ...

Rendering Error - Animating text using React and Material-UI

Looking for a way to create a scrolling effect line by line? I have a component with name, pronouns, and some humble sub-text that should scroll one item at a time. To handle the scrolling feature, I've set up a separate component called TitleScroll. ...

How to set up a Carousel as the background within a div using Bootstrap 5

I'm attempting to create a visually appealing layout by showcasing a Carousel component behind some text. The idea is to have scrolling and fading images with a prominent header overlaid on top of them. I want the carousel images to be contained withi ...

Why does my React.js application still display outdated data from my Express server even after refreshing the webpage?

I have been working on a website using React.js and Express.js, following an online example to set up the basic code. I encountered an issue where the frontend did not update when I made a minor change to the array sent by Express.js. Express - users.js f ...