Insufficient availability of courses in the Back Tick platform

function Home() {
  let displayCards = Galeyre.map((item) => {
    return `
        <div class="card_container">
            <div class="card">
                <div class="face-side">
                    <alt="Question mark">
                </div>
                <div class="back-side">
                    <alt="${item.name} flag icon">
                </div>
            </div>
        </div>`;
  }).join("");

No matter what I tried, the styling of the element classes in backticks is not working properly in the CSS section. How can I resolve this issue?

Answer №1

If you want to learn more about React, start by reading the documentation on how to get started. In essence, React is a UI library that revolves around state, with components built in JSX being reactive to changes in that state.

While you seem to be on the right path, it's important to note that React doesn't rely on back-ticks for creating HTML strings – all of this functionality is handled within the library itself. Your focus should be on understanding the syntax, grasping how state operates, and effectively organizing your components to respond to state changes.


This customized example based on your code snippet should provide you with some clarity:

const { useState } = React;

// Home component accepting deck as props
function Home({ deck }) {
  
  // Setting up state using the deck
  const [cards, setCards] = useState(deck);
  
  function handleClick(e) {
    const card = e.target.closest('.card');
    if (card) {
      const { dataset: { id } } = card;
      setCards(prev => {
        return prev.map(card => {
          if (card.id === Number(id)) {
            return { ...card, visible: !card.visible };
          }
          return card;
        });
      });
    }
  }
  
  return (
    <main>
      {cards.map(card => {
        return (
          <Card
            key={card.id}
            card={card}
            handleClick={handleClick}
          />
        );
      })}
    </main>
  );
}

function Card({ card, handleClick }) {

  const { id, symbol, visible } = card;
  
  return (
    <div
      data-id={card.id}
      className="card"
      onClick={handleClick}
    >
      <div className={`face ${visible && 'hidden'}`}>
        ?
      </div>
      <div className={`face ${!visible && 'hidden'}`}>
        {card.symbol}
      </div>
    </div>
  );
}

const deck = [
  { id: 1, symbol: '♠', visible: false },
  { id: 2, symbol: '♥', visible: false },
  { id: 3, symbol: '♦', visible: false },
  { id: 4, symbol: '♣', visible: false }
];

const node = document.getElementById('root');
const root = ReactDOM.createRoot(node);

root.render(<Home deck={deck} />);
.card { width: 75px; height: 100px; display: flex; align-items: center; justify-content: center; border: 1px solid black; font-size: 2rem; }
.card:hover { cursor: pointer; background-color: lightyellow;}
.hidden { display: none; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.development.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.2.0/umd/react-dom.development.min.js"></script>
<div id="root"></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

Navigating horizontally to find a particular element

I developed a unique Angular component resembling a tree structure. The design includes multiple branches and nodes in alternating colors, with the selected node marked by a blue dot. https://i.stack.imgur.com/fChWu.png Key features to note: The tree&ap ...

Transform the appearance of a button when focused by utilizing CSS exclusively or altering it dynamically

As a newcomer to coding, I am currently working on a project that involves changing the color of buttons when they are clicked. Specifically, I want it so that when one button is clicked, its color changes, and when another button next to it is clicked, th ...

Exploring the depths of Open Office XML structures

When working with HTML, it is easy to structure elements like this: <span id="outsideSpan"> <span id="insideSpan> Some Text </span> </span> In Open Office XML, there is no direct equivalent of "innerHTML" between ru ...

Change the navbar brand in Bootstrap to be hidden on small screens like mobile devices

I am facing an issue with the navbar on my website where it expands in height when viewed on mobile devices due to not fitting into a single line. I have observed that if I remove the brand, it fits perfectly. However, I want to keep the brand visible on l ...

Trouble retrieving element height with jQuery .load() function

Running into an issue with my script that utilizes jQuery .load() to load content onto a page. The content loads fine, and the animation for it (using class "hidden") is working smoothly. However, I'm encountering a problem where the wrapping containe ...

Adding a splash of color to a see-through image in the Yet-Another-React-Lightbox

I am currently working on implementing a react lightbox in NextJS, and I have a specific requirement to set the background color for a PNG image. Here is my Lightbox component setup: <Lightbox plugins={[Zoom]} open={open} closeOnBac ...

Guide on managing AngularJS / JavaScript dropdowns with Python and Selenium webdriver

I am looking to automate various browser tasks using Python and the Selenium WebDriver on the Chromium browser. My Python script is currently capable of logging in, navigating to a subpage, performing clicks, and entering information into a form. However, ...

Issue with Angular: PDF rendering delayed until window resize

Recently, I encountered an issue with rendering a PDF in Chrome while using an AJAX call with Angular. Strangely, the PDF would only show up in the browser if I resized the window or opened the console. Surprisingly, everything worked fine in Firefox. Jav ...

Is it possible to invoke a Python local function from an HTML document?

After creating a Python file with multiple functions, I am now working on designing a web page where I aim to trigger one of the functions mentioned earlier by clicking a button. However, I am unsure about how to go about this process. Is there anyone who ...

What could be causing unexpected results when Rails 2 encodes apostrophes in HTML?

When using h to HTML encode text in Rails 2, I'm encountering issues with apostrophes. Specifically, my apostrophes are being displayed as &#39;, which is not the desired outcome. Has anyone experienced this issue before? My understanding was tha ...

What is the best way to display a div when a drop down menu is selected as "No"?

I am currently working on a project involving a form where the address fields are initially hidden. When a user indicates that they have not ordered before by selecting "No" from the drop-down menu, I want the Address field to appear. The HTML for the dro ...

Tips for preventing constructor from being called when the route changes?

Currently, I am developing an app that incorporates webSockets (socket.io). The Layout component contains the initialization of the webSocket connection in the constructor: export default class Layout extends Component { constructor(props) { super ...

What is the best way to access the following element of an array within a for..of loop with an if statement in Javascript?

Need help with creating a word filter that checks if index 1 is 'dog' and index 2 is 'cat' in an array. What should be checked in the next index for 'word'? let textContainer = ['bird', 'dog', 'cat& ...

Guide on automatically extracting table rows and generating an Excel spreadsheet

I am currently working on a script that dynamically adds the first row (TH) to a table and then exports it to an Excel sheet. However, I am facing an issue where instead of appending each row, the script keeps stacking on top of the next table row. Below ...

What is the best way to utilize {...this.props} within a functional component?

I recently purchased a React-Native course on Udemy where the instructor used {...this.props} but unfortunately, it caused an error for me. The error message I received was: TypeError: undefined is not an object(evaluating '_this.props') Any ...

Accessing a component's function from an HTML view in a Vue application

I seem to be stuck in a tricky situation with Vue logic. I have a "list" component that retrieves results from an ajax call. The issue arises when I try to incorporate a search field. Here is what I currently have: search.vue <template> <div> ...

Filter an object by an array and display it based on this array using Viewjs

Trying to filter an object from an array using another array in a JSON feed that has one array with objects and object within objects: members = [ { id: 1, name: "Ruta" }, { id: 2, name: "Paul" ...

Navigating an array and organizing items based on matching properties

When I receive an array that looks like this: errors = [ { "row": 1, "key": "volume", "errorType": "Data type", "expectedType": "number", &quo ...

Show and conceal columns in HTML with the help of JavaScript

I need help with a webpage where I want to display a table with 2 columns and two rows (header and body). My goal is to use JavaScript to control the visibility of these 2 columns. The decision to show or hide the columns should be based on the values ...

What is causing ref.current to become null in the useEffect hook?

Utilizing the MUI Dialog to display the modal on my website, I have encountered a puzzling issue. Within the DialogContent, there is a div that should accept the reference. However, when attempting to retrieve this ref within my useEffect, it seems to be n ...