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.

ERROR FREE 世界のトップ企業がこぞって採用したMIT博士のミスを減らす秘訣
[ad] ERROR FREE 世界のトップ企業がこぞって採用したMIT博士のミスを減らす秘訣
邱強, 牧髙光里 (Kindle版)