# Avoiding Using React Style Attribute

## Why Not Using Style Attributes in React?

In react, the style attribute will force the browser to re-render the component every time due to the style object being new every react render.

There are two ways to solve this problem.

### Use a Class

In general, updating the style attribute of a React component on every render is not a good practice. This can cause the browser to unnecessarily re-render the component and impact performance.

Instead, it is recommended to use a CSS class to define the styles for a component and then apply the class to the component using the className prop. This allows the styles to be cached by the browser, improving performance.

Here is an example of how you might do this:

### Define the Style Object Outside the Component

Alternatively, you can use the style prop to apply inline styles to a component, but you should make sure to only update the style object when it is necessary. For example, you might define the style object outside of the component and only update it when specific props or state values change. This will ensure that the style object is not recreated on every render.

This code example shows how to save the Style Object Outside the Component so that it’s always the same instance.