When I use the JSX below to set inline styles programmatically, the page won't load. I've simplified the code to a trivial example to illustrate the problem.
const AboutPage = () => {
let buttonStyle = { color: 'red' };
return (
<div>
<input type="button" style="{buttonStyle}" value="Click Me" />
</div>
);
}
I get this error in the browser console:
The style prop expects a mapping from style properties to values,
not a string. For example, style={{marginRight: spacing + 'em'}} when
using JSX.
This is my first day learning React and JSX so I must be missing something obvious. But it seems like I'm doing the right thing: I'm putting an object (not a string) inside curly braces. Why does React interpret it as a string?