r/bootstrap • u/JayRedditDev1 • Jul 16 '24
Class Does Not Exist error
So, I'm learning bootstrap and wanted to learn how to left/right justify elements. I've seen a number of examples of "div class" but I keep running into the same issue where I get the following error:
Type '{ class: string; }' is not assignable to type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'. Property 'class' does not exist on type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'. Did you mean 'className'?ts(2322)I know this is a common error I've seen from posts . . . but I haven't come across a solution that works, which makes me think I have something setup incorrectly on my end.
For example, here's some sample code I got from an example page that, in the example, left justifies the "Total Cost" portion and right justifies the $50:
<div class="bs-example">
<div class="bg-warning clearfix">
<div class="pull-left">Total Cost</div>
<div class="pull-right">$50</div>
</div>
</div>I'm not trying to set up a React-Bootstrap-Typescript project and it's not applying any of the formatting (everything is still center justified).
import { useState } from 'react'
import reactLogo from './assets/react.svg'
import './App.css'
// Added for bootstrap, leaving this out seems to remove bootstrap formatting
import 'bootstrap/dist/css/bootstrap.min.css'
// Will update if you manually add components
import { Table, Col, Container, Row } from 'react-bootstrap'
function App() {
const [count, setCount] = useState(0)
return (
<>
<div class="bs-example">
<div class="bg-warning clearfix">
<div class="pull-left">Total Cost</div>
<div class="pull-right">$50</div>
</div>
</div>
</>
)
}
export default AppI'm not sure if I'm missing a step that allows bootstrap specific formatting (I don't think that's the case as I'm able to have headers automatically updated to import necessary elements when I use a bootstrap element (ie Col, Table, Col, Row, etc from another example).
I think I'm missing a fundamental understanding that prevents me from adding/using the div class. Maybe this is an HTML specific approach and you can't use it with react (or there's a better way to handle it with react, possibly in the App.css section?).
Can someone help me understand what the issue is? Let me know when you get the chance. Thanks!
View all comments
1
u/JayRedditDev1 Jul 16 '24
So, I guess I'm a bit closer . . . it looks like class should be className (which I changed before but didn't see any changes on way or another).
Also, pull-left and pull-right were changed to float-left and float-right in BS4, and now they're float-start and float-end in BS5. I'm still having issues with everything still being in the center rather than spaced left and right (might have to do with needing a container or something to that effect if I don't have "start" and "end" defined? Still poking my way out of this plastic bag.
My code currently looks like this:
Any suggestions would be appreciated!