How to use code of html/css in react/bootstrap?
Code in react js using bootstrap
How to use components and props?
It is showing errors even after installing bootstrap.
Can we use html/css code directly into react files into different folder..
how do we need to apply bootstrap to it.
please guide me through it.
3
Answers
Sure, let’s break it down into simple steps:
Create a New React App: First, make a new React app if you don’t have one already. Think of it like creating a new project folder.
Install Bootstrap: Imagine it’s like getting a new tool. You can install Bootstrap, which is a handy set of styles and components for your app.
Import Bootstrap CSS: It’s like telling your app to use those new styles. You import the Bootstrap styles into your app so it knows how to look nice.
Create React Components: Think of these like building blocks for your app. You can make separate files for things like headers and footers to keep your code organized.
Use React Components: Now, you can put those building blocks into your app. For example, you can add a header and a footer to your main app page.
Custom CSS: If you want to make things look even more special, you can create your own styles in CSS files and use them in your components.
Passing Props: Imagine props as messages you send to your components. You can tell your components what to show by passing them these props.
Handling Events: If you want your app to react when someone clicks a button or does something, you can use event handling, just like you do in regular HTML.
Remember the Structure: In React, components should always give back one main thing. If you want to show multiple things, you put them inside a container.
By following these steps, you can use HTML, CSS, and Bootstrap in your React app. You can also make cool components, send messages to them, and make them do things when someone interacts with your app.
I am going to write steps down here:
1. Create react app first using
2. Next install bootstrap in it not react-bootstrap
3. Now import bootstrap CSS into your entry file so that index.js file
4. Now you can use bootstrap classes into your code as given here
5. Now you can pass the data to by creating your components as shown below
Along with bootstrap classes you can also use your custom CSS. You need to import your custom css files as you imported bootstrap css file.
Hopefully, this will help you. Feel free to ask questions.
The previous answers assume that you will be using CSS as your primary language for writing styles, which may not be what you want.
The reasons why you may not want to import a CSS file are:
If you want to use SASS as your style writing language, don’t import bootstrap CSS file into you component Typescript or JavaScript source.
Have each component come with and index.scss file, that
@use
bootstrap mixins, functions and variables to theme your component. And use a proper build toolchain capable of compiling those SASS files alongside the rest of the project.There are many of them available. I’m myself maintaining one of them so if you are interested by a more thorough answer about that point, please comment and I’ll update this answer.
You’ll end up with more maintainable, readable and testable code, dramatically smaller stylesheets that only come with the rules that your app actually uses and way less bugs due to styling collisions.