Rules not being applied to styled components due to emotional influence

I'm attempting to utilize the emotion library.

Here is my JavaScript code:

import React from 'react';
import { css } from '@emotion/core';

export const Menu = () => (

  <>
    <nav
      css={css`
        position: absolute;
        color: white;
      `}
    >
      <h1
        css={css`
          color: white;
        `}
      >
        Title
      </h1>
      <ul>
        <li>Projects</li>
        <li>Blog</li>
        <li>About</li>
        <li>Contact</li>
      </ul>
    </nav>
  </>;

);

export default Menu;

Upon inspecting the element, this message appears instead:

You have attempted to stringify an object returned from the css function. It should not be used directly (e.g. as a value of the className prop), but rather passed to emotion so it can handle it (e.g. as a value of the css prop).

Answer №1

Implementing the JSX Pragma with jsx function from '@emotion/react' enables the use of the css prop.

Check out the documentation here:

/** @jsx jsx */
import { jsx } from '@emotion/react'
import { css } from '@emotion/core'

const App = () => (
  <nav
    css={css`
      position: absolute;
      color: white;
    `}
  >
    <h1
      css={css`
        color: white;
      `}
    >
      Title
    </h1>
    <ul>
      <li>Projects</li>
      <li>Blog</li>
      <li>About</li>
      <li>Contact</li>
    </ul>
  </nav>
)

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

What is the best way to retrieve the input values in React components?

I am currently working on a regular page using next js framework. The structure of my page involves generating input fields dynamically with the help of a component called "SubjectInput". Here's an overview of how it looks: "use client" imp ...

Error: The function explore() is missing a required parameter called 'path'

Here is my code snippet: def navigate(directory): # To avoid issues with forward slashes, normalize the path directory = os.path.normpath(directory) if os.path.isdir(directory): subprocess.run([FILEBROWSER_PATH, directory]) elif os.path.isfile(directo ...

Leverage TypeScript Enum along with PropTypes to declare the properties of a React component

Upon having the Component and utilizing a TypeScript Interface for defining its props: interface Props { headerType: DROPDOWN_MENU_TYPE, //DROPDOWN_MENU_TYPE is enum headerContent: SVGClass isReverse: boolean; }; const MyComp: React.FunctionC ...

React frontend encountering an undefined environment variable

I am having trouble using an API key for one of my frontend components. Although require('dotenv').config() works fine in my backend, it doesn't seem to work here. Could it be that I need to specify a relative path for it to function properl ...

Issues with Swiper functionality in Jquery Mobile

I have implemented the Swiper plugin by idangero.us along with jQuery Mobile... In this case, I am utilizing the Scroll Container Swiper for a content slider... However, I am encountering several difficulties when trying to integrate the code... You can ...

Utilizing propTypes with React destructuring

I'm currently encountering an issue while trying to implement validation using propTypes: class MediaBrowse extends React.Component { render() { const { name, age, array } = this.props.data; return (<div></div>) } } Despite s ...

Position an element in the middle of the range between the tallest and shortest characters

Is there a way to vertically center an element between the tallest and shortest characters of another element (preferably using just CSS, but JavaScript is also acceptable)? I want it to be aligned with the actual text content rather than the line height, ...

I'm having trouble understanding why the MUI CORE basic rating code is returning undefined for setValue. Can anyone help

My first experience with MUI CORE was not smooth as I encountered an error when trying to use active rating and the set value is not defined i mport './App.css'; import 'bootstrap/dist/css/bootstrap.min.css'; import Movie from './ ...

Unusual Floating Glitch

I'm working on a Modal Box that contains responsive images. Code: http://jsfiddle.net/YCcNY/34/ When hovering over the images, they enlarge. However, there seems to be an issue with the last image in the first row, as it sometimes breaks the layout ...

Maximizing the potential of website positioning properties

<head> <style> .body { margin: 0 0 0 0; .navigation { background-color: lightyellow; width:100%; height:20%; position:fixed; } .slider{ position: absolute; top:20% height:60%; width:100% ba ...

Implement a functionality in React js where upon clicking a button, new li elements are added to

I am attempting to insert a new li element into the ul element within the CommentList return div. This li element should include the user input from the <input type="text" /> field. The error message I am encountering is: 'Cannot read ...

Struggling with pagination when dealing with numerous identical HTML elements within a single file?

I am in the process of creating a web app for a small CTF that will be held at my school. I have designed a webpage to display the problems, but currently they are all lined up in a long row. This is how it's set up: <body class="main-body"&g ...

Undefined key in React is not valid syntax

Every time I run this code on my localhost, it displays an error message saying "key is not defined". import React from 'react'; import PropTypes from 'prop-types' class LineTable extends React.Component{ supprimerLine = key => { ...

Text animation that rises smoothly within a concealed overflow region

I'm currently trying to replicate the effect seen in this example: Specifically, I am referring to the text that reads "CREATIVE AGENCY FOR DARING BRANDS" Although it appears simple, I am having trouble figuring out how to achieve it. I primarily wo ...

"Adjusting the height of Material UI card content to ensure fixed positioning at the bottom

Currently, I am working on mapping material-ui cards with dynamic content from a JSON object, resulting in varying card heights. I have successfully set a fixed height for each card, but the content is not aligned correctly. You can see the issue in this ...

What is the best way to set the value of the days in a month to a div

I've been experimenting with creating a calendar using javascript, HTML, and CSS on my own. I managed to achieve some functionality like obtaining the current month and year as well as the previous month and year by clicking a button in HTML. However, ...

Unexpected behavior with the background property in CSS

Visit the live webpage Searching for a solution to showcase code snippets on my site, I'm faced with a challenge as a CSS beginner. My struggle lies in creating a dark background for displaying these code snippets. Upon trying to implement a class n ...

React.js Components - Drawer overlays webpage content

I made the decision to include the Drawer component in my React project from the material-ui library. This is how I implemented it: class RightDrawer extends React.Component { state = { open: false, }; handleDrawerOpen = () => { this.set ...

What is the best way to center a text and a rectangle (containing some text) on a page using Bootstrap?

I'm in the process of creating a webpage using HTML and CSS that needs to look exactly like this image: https://i.sstatic.net/wYKZw.png Currently, I have a version of it on JSFiddle. The issue with the JSFiddle version is that the text and rectangle ...

Implementing a persistent header on a WordPress site with Beaver Builder

My website URL is: . I have chosen to use beaver builder for building and designing my website. I am in need of a fixed header that can display over the top of the header image. Here is the code snippet that I currently have: <div id="header">html ...