Issue with radio group default checked input in a next.js application utilizing TypeScript and Tailwind CSS

After utilizing next.js, I created a webpage that allows users to select from 3 different menus and then view a bar graph generated by Chartjs based on the selected information. Each menu comes with a default value already set.

I've encountered a bug where the checked label does not display correctly for one of the menus. (Upon refreshing the page, I briefly see it being checked and then unchecked). Below is the code snippet for the menu component. Any assistance in fixing this bug would be greatly appreciated!

'use client'

interface SocialValueGroupProps {
    selectedSocialValue : string,
    handleSelectValue : (value: string) => void
}

const SocialValueGroup = ( props: SocialValueGroupProps) => {

    const socialValues: { id: string, name: string }[] = [
        { id: "work_score", name: "Importance of work" }, 
        { id: "fam_score", name: "Importance of family" },
        { id: "religion_score", name: "Importance of religion"},
        { id: "gender_equality", name: "Importance of gender equality"},
        { id: "ethnic_rel_tolerance", name: "Ethnic and religious tolerance"},
        { id: "sex_minority_tolerance", name: "Tolerance of sexual minorities"}]


    function handleChange(event: React.ChangeEvent) {

        props.handleSelectValue(event.target.id)
        
    }

    return (

        <div className="w-full">
            <fieldset>
                <div className='grid-cols-1 px-5 mt-5'>
                <h2 className='text-black text-2xl'>Select a social value</h2>
                    {socialValues.map((socialValue: { id: string, name: string }) => (
                        <div key={socialValue.id} className='px-5 my-2'>
                            <input
                                type="radio"
                                id={socialValue.id}
                                value={socialValue.name}
                                name="social_value"
                                className="hidden peer"
                                onChange={handleChange}
                                defaultChecked={props.selectedSocialValue == socialValue.id}
                            />
                            <label
                                htmlFor={socialValue.id}
                                className="block w-full px-4 py-2 rounded-full bg-gray-300 text-gray-800 cursor-pointer hover:bg-gray-400 transition-colors
                         peer-checked:bg-indigo-300"
                            >
                                {socialValue.name}
                            </label>
                        </div>

                    ))}
                </div>
            </fieldset>
        </div>
    )
}

export default SocialValueGroup

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 push method in Typescript does not have the capability to capture a tuple type within an array

const testArray:[number, string] = [10, 'test', 's']; It's not functioning correctly. const testArray:[number, string] = [10, 'test']; // Changes have been made. testArray.push('test'); Now it's working a ...

Transfer the output of a function in a service to a different function

I have a unique service that connects to 2 different API endpoints. The first endpoint retrieves the user's id along with a JWT token: @Injectable() export class UserService { appLogin = 'http://url.for.the.login.api'; //returns id an ...

What is the best way to apply the default MUI5 theme and customize the styling of individual components in MUI5?

import { styled } from "@mui/system"; import { CardTravel, Home, People } from "@mui/icons-material"; import { Box, Container, Typography } from "@mui/material"; import React from "react"; const BoxContainer = style ...

Troubleshooting the issue of process.nextTick not being recognized in Calgolia places.js

After successfully implementing Algolia's places.js in my Angular 7 project using NPM, I encountered an issue. I have integrated a form where one of the fields should be an input. <form [formGroup]="myForm"> <pre style="color: white; b ...

How disabling SSR is causing my styles to break in Nextjs

My Nextjs app is causing some issues with styling when I disable SSR to connect to Metamask using the window object. Specifically, the Navbar title style changes when SSR is disabled and the dev server is restarted: With SSR enabled: https://i.sstatic.net ...

Upon selecting the hamburger menu, the menu pops up; however, the homepage text is visible overlapping the menu

I'm in the process of developing a responsive portfolio page using ReactJS and Tailwind CSS. When the screen size is smaller than the medium breakpoint, a hamburger menu icon appears. However, when I click on the hamburger icon to view the menu items, ...

When running npx ts-lint in a Docker environment, an error occurs stating that the module 'typescript' cannot be found

In the process of setting up a dockerized development environment for a node/typescript API project, I am aiming to have everything run within Docker without the need for node, npm, or modules installed on the host system. The main objective is to isolate ...

Caution: NextJS indicates that each child within a list requires a distinct 'key' prop to avoid errors

Currently, I am delving into the functionality of getStaticProps in NextJS. My project involves fetching data from the JSONPlaceholder API to display posts on a webpage. Here is a snippet of my JavaScript file: function PostList({posts}){ return ( ...

The addition operator is not compatible with the given types

Hello, I am currently working on integrating PayPal into an Angular 5 project. The code snippet below shows how I render PayPal buttons using a function: ngAfterViewChecked(): void { if (!this.addScript) { this.addPaypalScript().then(() => { ...

The argument '$0' provided for the pipe 'CurrencyPipe' is not valid

When retrieving data from the backend, I receive $0, but I need to display it as $0.00 in my user interface. <span [innerHTML]="session.balance | currency :'USD': true:'1.2-2'"></span> I'm encountering an issue where ...

Using Python Selenium, learning how to select a radio button is a key skill

I am attempting to select the "Monthly (Final)" Radio Button in the tab on the left side. Can you please click on the following link to access the information? Below is the code I have used: from selenium import webdriver import time chrome_path = r"/u ...

Arrange elements within an array according to a specific property and the desired sorting sequence

Looking for a way to sort an object array in Angular 16+ based on status. The desired status order is: [N-Op, Used, Unknown, Op] Here's the sample data: const stockList = [ { 'heading': 'SK', 'status': &a ...

Guide on transferring the marker icon between two geographic coordinates through Leaflet OpenStreetMap within an Angular environment, sourced from the API

In my Angular application, I have integrated the Leaflet open street map for displaying a map. The latitude and longitude array has been retrieved from an API as follows: { "Drone": { "Droneid": 1001, "latlong": [ ...

Establishing connections between existing records via explicit many-to-many relationships in Prisma

My goal is to link two existing records using prisma.update in order to create an entry on a specific many-to-many table. I'm having trouble identifying what's missing. schema model User { id String @id @default(uuid()) cats Use ...

Transform radio inputs into buttons when they are enclosed within a label element

This is my HTML code: <div class="product-addon product-addon-extra-tip"> <p class="form-row form-row-wide addon-wrap-2004-extra-tip-0-0"> <label><input type="radio" class="addon-radio" name="addon-2004-extra-tip-0[]" valu ...

Could you provide an explanation of the styled() function in TypeScript?

const Flex = styled(Stack, { shouldForwardProp: (prop) => calcShouldForwardProp(prop), })<LayoutProps>(({ center, autoWidth, autoFlex, theme }) => ({ })); This syntax is a bit confusing to me. I understand the functionality of the code, b ...

Utilizing Typescript DOM library for server-side operations

I've been working on coding a Google Cloud Function that involves using the URL standard along with URLSearchParams. After discovering that they are included in the TypeScript DOM library, I made sure to add it to my tsconfig file under the lib settin ...

Create celestial bodies based on the model variable

I am currently working on a rating star feature that dynamically displays stars based on information retrieved from the database. Within my app.ts file, I have declared a variable like so: this.rating = 4; Here is an example of how the HTML looks: < ...

The deployment of the Next.js app is successful on Vercel, however, it encounters issues when deployed on Ampl

I've been attempting to deploy my next.js app on AWS Amplify, but unfortunately, it keeps failing every time. I have set up a Git CI/CD pipeline for deployment. Interestingly, when I deployed the same app on Vercel, it only took 60 seconds and worked ...

Incorporating a Link/Template Column into Your Unique Table Design

I built a table component following the guidelines from this article: Creating an Angular2 Datatable from Scratch. While I have added features like sorting and paging to suit my app's needs, I am struggling with implementing a "Template column" to al ...