created: 2022-06-12T01:58:44.387Z

Reactのstyle属性に渡すオブジェクトのTypeScriptの型と公式ドキュメントの案内

React.CSSProperties を使う。

const s: React.CSSProperties = { width: "100%" };

参考

よく忘れるが、React の型情報は DefinitelyTyped で管理されている。

その他

CSSProperties でやるのは公式のドキュメントによると not recommended

Some examples in the documentation use style for convenience, but using the style attribute as the primary means of styling elements is generally not recommended.

公式は CSS-in-JS については「よくわからなかったら、とりあえず CSS-in-JS を使う前にまずこれまで通りの css ファイルを使ってみてはどうだろう」というスタンス。

a good starting point is to define your styles in a separate *.css file as usual and refer to them using className.

すぐわかる代数
[ad] すぐわかる代数
石村 園子 (単行本)