You are not using the props as far as I can see and besides that props are immutable. You might want to look into state and use that as the backGroundColor but for inline styling it could look like this

 <div style={{color: condition ? "red": "green"}}> </div>

EDIT: Seems like there is no styling intended for the NavItem. See here. You have to use css for that e.g. Change the <a> element class in react-bootstrap NavItem

Answer from Murat Karagöz on Stack Overflow
🌐
Oida
oida.dev › typescript-react › styles
TypeScript and React: Styles and CSS
If you want to get all the class names, and really nice auto-completion, drop the ambient files and include another loader: css-modules-typescript-loader · Styling requires a bit of infrastructure. Here’s some demos to get you started. This Codesandbox has samples for inline styles, style imports, emotion and styled components.
🌐
CodeSandbox
codesandbox.io › s › react-typescript-custom-inline-style-5meh2
React typescript custom inline style - CodeSandbox
September 15, 2021 - React typescript custom inline style by thinhlesdev using react, react-dom, react-scripts
Published   Sep 15, 2021
Author   thinhlesdev
Discussions

Support using `.css?inline` imports in TypeScript
Vite allows to bypass automatic CSS page injection for an import by appending ?inline suffix: https://vitejs.dev/guide/features.html#disabling-css-injection-into-the-page Unfortunately, imports of .css?inline are considered as TypeScript... More on github.com
🌐 github.com
0
April 11, 2023
React Tsx with React Bootstrap - Inline CSS for Active NavItem - Stack Overflow
I would like to change the background color for the active NavItem element to green using inline CSS. I'm using TypeScript 2.2, React, React Bootstrap, React Router Dom and React Router Bootstrap. Is More on stackoverflow.com
🌐 stackoverflow.com
reactjs - Typescript error during inline fontWeight style in React - Stack Overflow
Another way around it is to use CSS Modules or Styles Components. Also note, Typescript appears to only throw errors when defining CSS attributes that are originally hyphenated. More on stackoverflow.com
🌐 stackoverflow.com
reactjs - How to define css variables in style attribute in React and TypeScript - Stack Overflow
@SGhaleb I've seen this, in my ... the app, so it's the problem with typescript typings not with react. ... @KyawSiesein this is completely valid and normal in Design Systems. You certainly CAN define local CSS Variables inline.... More on stackoverflow.com
🌐 stackoverflow.com
🌐
DhiWise
dhiwise.com › post › how-to-elevate-ui-design-using-react-cssproperties-typescript
Implementing React CSSProperties Typescript for Styling
May 20, 2024 - Inline styles in React are applied using the style prop, which accepts an object where the keys are camelCased versions of the CSS property names, and the values are the CSS values as strings.
🌐
ReactHustle
reacthustle.com › blog › how-to-set-inline-styles-in-react-typescript
How to set inline styles in react (Typescript) | ReactHustle
Notice that I added xxx property to the style and typescript does not complain or throw any error. In order to add type safety and intellisense to the style object we have to declare it as a CSSProperties type.
🌐
npm
npmjs.com › package › @types › inline-css
@types/inline-css - npm
May 5, 2025 - TypeScript definitions for inline-css. Latest version: 3.0.4, last published: 7 months ago. Start using @types/inline-css in your project by running `npm i @types/inline-css`. There are 9 other projects in the npm registry using @types/inline-css.
      » npm install @types/inline-css
    
🌐
GitHub
github.com › vaadin › hilla › issues › 890
Support using `.css?inline` imports in TypeScript · Issue #890 · vaadin/hilla
April 11, 2023 - declare module '*.css?inline' { import { CSSResultGroup } from 'lit'; const content: CSSResultGroup; export default content; }
Author   platosha
Find elsewhere
Top answer
1 of 5
54

Typescript can be awfuly silly sometimes. It's inferring the type of fontWeight as a string, even though it could narrow it to its exact literal. You can just cast it as itself to fix this:

const boldText = {
    fontWeight: 'bold' as 'bold'
}

<td style={boldText}>Content</td>

These days you can also use the new as const declaration at the end of your literals for the same effect:

const boldText = {
    fontWeight: 'bold'
} as const;

<td style={boldText}>Content</td>

And finally, you can always provide an explicit type to the object when you declare it:

const boldText: React.CSSProperties = {
    fontWeight: "bold"
};

<td style={boldText}>Content</td>
2 of 5
6

Typescript sees boldText as a "normal" object, and so infers boldText.fontWeight as string:

const boldText = {
    fontWeight: 'bold' // <-- TS doesn't know more than this is a string
}

The code <td style={boldText}>Content</td> expects CSSProperties, so a string can't be assigned.

To solve the mismatch, you can tell Typescript the type of the object:

const boldText: CSSProperties = {
    fontWeight: 'bold'
}

To be more precise:

  • e.g. color: '#ff0000' would work, because color accepts values of type string.
  • fontWeight: 'bold' doesn't work, although fontWeight accepts "bold", because TS decides to use the type string before it knows about the context of CSS, and the type string is not the same as the type "bold" | "bolder" | 100 | 200 | ...:
const boldText = {
    fontWeight: 'bold'  // <-- TS makes it's decision for type 'string'
    color: '#ff0000'    // <-- TS makes it's decision for type 'string'
}

// TS doesn't complain about color, as color accepts NamedColor | string | ...
// TS only complains about fontWeight, as it accepts only "bold" | "bolder" | 100 | 200 | ...
const TD = <td style={boldText}>Content</td>
🌐
GitHub
github.com › topics › inline-styles
inline-styles · GitHub Topics · GitHub
December 12, 2022 - Concise way to write runtime inline CSS styles.
🌐
Medium
medium.com › @m.mondik › how-we-handle-inline-styles-with-typescript-and-react-2c257e039f2b
How we handle inline styles with TypeScript and React | by Michal Mondík | Medium
August 10, 2018 - How we handle inline styles with TypeScript and React A typical project at Blueberry consists of several apps (typically 4 to 6), with each having an almost identical design. The commonest process …
🌐
Webdevtutor
webdevtutor.net › blog › typescript-css-inline
Mastering Inline CSS in TypeScript
To start using inline CSS in your TypeScript projects, you can simply create a style object and apply it directly to your elements.
🌐
Webdevtutor
webdevtutor.net › blog › typescript-inline-css-variable
Using TypeScript with Inline CSS Variables - A Comprehensive Guide
Inline CSS variables, also known as custom properties, allow developers to define reusable values within CSS rules. These variables can be used to store colors, font sizes, spacing values, and more, making it easy to maintain consistency throughout the project.
🌐
npm
npmjs.com › package › inline-css
inline-css - npm
December 27, 2024 - This module takes html and inlines the CSS properties into the style attribute.
      » npm install inline-css
    
Published   Dec 27, 2024
Version   4.0.3
Author   Jonathan Kemp
🌐
Stack Overflow
stackoverflow.com › questions › 72508657 › how-can-i-implement-an-error-free-dynamic-in-line-style-in-react-with-typescript
css - How can I implement an error-free dynamic in-line style in react with typescript? - Stack Overflow
So after quite some searching, I finally found the answer. Basically, it is not possible to pass the style as a variable in Typescript. Instead, the style has to be applied directly inline.
🌐
Codersera
codersera.com › blog › complete-guide-to-inline-style-in-a-react-app
Complete Guide To Inline Style In A React App
March 31, 2023 - Also Read | React Hooks With Typescript : UseCallback, UseMemo, UseContext And UseRef · Need to write redundant CSS properties individually for each element. CSS properties will be limited to a component scope only, so there is no reusability · It’s impossible to style pseudo-elements, pseudo-classes, media queries, etc with inline styles.
🌐
Reddit
reddit.com › r/reactjs › inline css variables
r/reactjs on Reddit: Inline CSS Variables
May 14, 2022 -

I am trying to create a component that sets CSS Variables using the inline style attribute. Example:

<div style={{'--item-color': props.color}}>...</div>

Is this possible with react? I can't find any documentation or previous conversation on the topic. All I can find is using DOM CSS properties like backgroundColor: ....

The above example would give the following error:

Type '{ '--item-color': string; }' is not assignable to type 'Properties<string | number, string & {}>'.Object literal may only specify known properties, and ''--item-color'' does not exist in type 'Properties<string | number, string & {}>'.ts(2322)