What are some ways to leverage props in React to avoid unnecessary duplication?

How can I utilize props to avoid this repetition in my code??

import React from "react";

export const FindUs = () => {
  return (
    <div className="p-[6%]">
      <div className="text-landing-title font-semibold text-4xl ">
        Find us
      </div>
      <div>
        <div className="block text-landing-footer-contactUs text-lg font-medium mb-3 mt-9">
          Address
        </div>
        <div className="text-landing-text font-normal text-sm leading-5 pt-2">
         
        </div>
      </div>
      <div>
        <div className="block text-landing-footer-contactUs text-lg font-medium mb-3 mt-9">
          Email Address
        </div>
        <div className="text-landing-text font-normal text-sm leading-5 pt-2">
          
        </div>
      </div>
      <div>
        <div className="block text-landing-footer-contactUs text-lg font-medium mb-3 mt-9">
          Phone Number
        </div>
        <div className="text-landing-text font-normal text-sm leading-5 pt-2">
         
        </div>
      </div>
    </div>
  );
};

Answer №1

import React from "react";

const Location = ({point}) => (
      <div>
        <div className=" block text-map-marker-location text-lg font-medium mb-3 mt-9">
          {point}
        </div>
        <div className="text-map-address font-normal text-sm leading-5  pt-2">
         
        </div>
      </div>
)

export const ContactUsInfo = () => {
  return (
    <div className="p-[6%]">
      <div className="  text-heading-title font-semibold text-4xl ">
        Contact Information
      </div>
      {['Address', 'Email Address','Phone Number'].map(point => <Location key={point} point={point} /> }
       
    </div>
  );
};

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

Error: Bootstrap CSS missing from app created with create-react-app-ts

I have a React application that was initially set up using create-react-app-ts. Although I have included bootstrap and react-bootstrap for navigation, the CSS styling from Bootstrap does not seem to be applied properly. The links do not display any styling ...

Having troubles with delayed state changes due to setState being used within useEffect

I have been working on a slider effect using React Hooks and Redux, and here is the code I am using: const Barchart = ({chartData}) => { let newArray = [] let len = chartData.length const [XArray,setXArray]=useState([chartData]) const [ ...

React Native: Image display issue

I'm facing a problem with displaying an image. I've followed all the steps correctly as per a tutorial, but for some reason, my image is not showing up while the author's images are displayed perfectly. What could be causing this issue? I ha ...

Maximizing page space with ReactJS and advanced CSS techniques

I'm currently in the process of learning CSS and struggling a bit with it. My main issue right now is trying to make my react components fill the entire height of the browser window. I've been using Display: 'grid' and gridTemplateRows: ...

Looking for a way to activate a button that triggers the drag animation (translateX) for card demonstrations?

Here is the situation I am dealing with: I am in need of a feature similar to Tinder, where I can initiate the same transition as dragging. Specifically, I am attempting to implement like and dislike button functionality similar to Tinder. However, due t ...

Audio suddenly no longer working after transferring project to React

View my reproducible example here. This is a demonstration of the issue I am facing. Previously, when the page consisted only of static html with javascript, the sounds were functioning correctly. However, after refactoring into a React app, the sounds ha ...

Generating interactive cards using an array

In an attempt to showcase information for three separate months using a single component, I am creating cards titled "Month 1," "Month 2," and "Month 3." Each card contains a table, and I am aiming to add headers to each card based on an array of titles. ...

Setting a default value for Autocomplete in MaterialUI and React.js

Is there a way to set a default value for an Autocomplete TextField component from Material UI in React.js? I want to load a pre-populated value from the user's profile that can then be changed by selecting another option from a list. Check out my co ...

Warning: React has detected that a non-boolean value of `true` was received for the attribute `my-optional-property`

source code import React from "react"; import { Button, ButtonProps } from "@material-ui/core"; interface MyButtonProps extends ButtonProps { "aria-label": string; "my-optional-property"?: boolean; } function MyCustomButton(props: MyButtonProps) { ...

I'm facing a CORS dilemma and I'm seeking assistance to resolve it

I've been struggling with CORS issues and have tried every method possible to resolve it, but without success. Here is the screenshot of my code: https://i.stack.imgur.com/2gTF4.png Below is the request from my React app: https://i.stack.imgur.com/W ...

The Material UI Drawer stays closed despite the state being set to true

Currently, I am in the process of developing a WebApp utilizing React and Material UI. Despite following numerous tutorials on implementing the Drawer component and poring over the documentation, I am still struggling to grasp its functionality. Even thou ...

Developing a NextJS application within an existing Firebase project

Currently, I am looking to leverage NextJS on Firebase for hosting my website. While the online resources available have guided me through setting up a NextJS app and initializing a Firebase project, my situation is slightly different. I already have exi ...

Flickering of CSS in Nextjs

Currently, I am in the process of developing a React application using Material UI and Next.js. To customize the appearance of the <Autocomplete /> component provided by Material UI, I am overriding some of its styles with my own defined styles like ...

Steps for implementing AsyncStorage in a React Native application to store data on both TextInput and Picker components

I recently attempted to learn how to utilize the AsyncStorage feature on the React Native website, but unfortunately, I found the concept quite challenging to grasp. My goal is to implement AsyncStorage in my React Native application by saving data from th ...

What is causing the TypeScript error in the MUI Autocomplete example?

I am attempting to implement a MUI Autocomplete component (v5.11) using the example shown in this link: import * as React from 'react'; import TextField from '@mui/material/TextField'; import Autocomplete from '@mui/material/Autoco ...

Interact with concealed form using Semantic UI React reveal feature

I am using Semantic UI React's Reveal component with two different Cards - one visible and the other hidden. The hidden Card contains a form and button that I need to interact with. Is there an easy way to make the form accessible, or do I need to fin ...

Encountered Error : Uncaught Rejection (SyntaxError): JSON data ended unexpectedly

I'm facing a challenge with fetching in React as I attempt to connect my Node API running on port 8000. Everything was working smoothly initially until I introduced a fetch for another function, resulting in the following error message: const API_URL ...

Establish the starting value for the material user interface checkbox

function mapStateToProps(state) { return { model: Selectors.Quotes.getCurrentQuote(state), }; } class Customer extends Component { state = { checkedEnergyConcessionHolder: false }; ...

Error in RatingBar component: Vue.js 3 and Tailwind CSS not displaying dynamic width correctly

I have a component called RatingBar in Vue.js 3 with Tailwind CSS. My goal is to dynamically adjust the width of the parent element's class based on a value, but even though I see the desired width in DevTools, it always renders as 100%. Below is the ...

Using Unicode JSON in Laravel blade to pass data to React components, encountering an issue with JSON parsing

I currently have a JSON object stored in the database: { "ui": {}, "title": "Hola mundo 2", "values": {}, "properties": {}, "description": "descripcion" } Within the Laravel controller, ...