2

I am working on integrating react package of content builder.

There are lots of files which needs to be keep in public folder and then add the references of css and js in index.html file

<link href="/assets/minimalist-blocks/content.css" rel="stylesheet" type="text/css" />
    <link href="/assets/ionicons/css/ionicons.min.css" rel="stylesheet">
    
    <script src="/contentbuilder/lang/en.js"></script>
 <script src="/assets/minimalist-blocks/content.js" type="text/javascript"></script>

Now the css is breaking all others application styles.

I am thinking to import css files in only the component where package is required, but since I am not aware of how to import from public folder, I copied above two css files and put inside the src folder and imported. but it seems css files are using some other css fonts etc. so its not able to work...

Can anyone guide me how to import the css files from public folder to any component.

Thanks

1

5 Answers 5

2

You can use tag to include a css file in your React app.

<link rel="stylesheet" href="%PUBLIC_URL%/style.css"  type = "text/css" />

Unfortunately, we can not import a css file from the public folder into a JavaScript file (React components).

To import a css file in React components you have to move your style.css file to the src folder and import the file in App.js like this

import './style.css';
Sign up to request clarification or add additional context in comments.

1 Comment

as I said already tried this, but this css has internally linked with other files, so its not working
0

Check how your back end is processing requests

React Router does not handle static files normally

Check if the app is using Express in back end, and add this:

app.use(express.static('public'));

Comments

0

The link tag isn't closed I guess it's a really really tiny typo. If you observe the highlighted link tag isn't closed. Just make the tag self-closing. That should have fixed it

<link href="/assets/ionicons/css/ionicons.min.css" rel="stylesheet" />

Observe the /> instead of just > at the end

Comments

-1

You can use the <link /> tag in side components' render functions:

return (
<>
    <link href="/assets/minimalist-blocks/content.css" rel="stylesheet" type="text/css" />

    ...
</>
)

Comments

-2

Write the css style in locally in your react app?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.