Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

268
Views
Componentes de estilo React JS que importan imágenes desde una carpeta pública

He estado tratando de configurar la imagen como imagen de fondo desde la carpeta pública en componentes con estilo. lo intenté así

 import styled from "styled-components"; import Background from 'process.env.PUBLIC_URL + /images/background.svg' export const HomeContainer = styled.section` height: 100vh; max-width: 100vw; background-image: url(${Background}); background-repeat: no-repeat; background-size: cover; `;

y entonces

 import styled from "styled-components"; export const HomeContainer = styled.section` height: 100vh; max-width: 100vw; background-image: url('process.env.PUBLIC_URL + /images/background.svg'); background-repeat: no-repeat; background-size: cover; `;

¿Cómo puedo importarlo? Gracias por adelantado

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Lo he buscado en Google, pero todavía no tengo nada como tú.

Así que decidí usar accesorios:

 import styled from "styled-components"; const HomeContainer = styled.section` height: 100vh; max-width: 100vw; background-image: url(${ ({Background}) => Background }); background-repeat: no-repeat; background-size: cover; `; const App = () => { return ( <HomeContainer Background={ process.env.PUBLIC_URL + 'where your image at' } /> ) }
about 4 years ago · Juan Pablo Isaza Report

0

Le recomiendo que tenga el archivo jsconfig configurado con la ruta base

 { "compilerOptions": { "jsx": "react", "baseUrl": "./", } }

Y luego acceda a su imagen simplemente import img from "public/images/whatever.png

about 4 years ago · Juan Pablo Isaza Report

0

Prueba esto, me está funcionando.

 import bgImage from "../images/background.png"; const Wrapper = styled.div` background-image: url(${bgImage}); `
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!