Б
Size: a a a
Б
M
Б
К
で
で
Б
Б
const SomeComponent = () => {
return <div style={{
width: 100,
height: 200,
backgoundColor: "blue"
}}>
<div style={{....}}></div>
<div style={{....}}></div>
<AnotherComponent prop1={..} prop2={}/>
</div>
}
const AnotherComponent = () => {
return <div style={marginTop: 10, ...}>
...
</div>
}
//хелперыИ я уже довольно давно пишу на реакте таким образом (вместо транспиляции jsx вызываю React.createElement напрямую в атомарных компонентах).
const Div = (style, children) => React.createElement("div", {style}, children);
const component = (Component) => (props) => React.creatElement(Component, props)
//компоненты
const SomeComponent = component(() => {
return Div({
width: 100,
height: 200,
backgoundColor: "blue"
}, [
Div({...})
Div({...})
AnotherComponent({prop1: ..., prop2: ...})
]})
})
const AnotherComponent = component(() => {
return Div({style: marginTop: 10 }, [
...
])
})
const SomeComponent = () => {
return Frame({
width: 500,
height: 500
children: [
Frame({
paddingTop: 10,
children: [
Frame({
marginLeft: 10,
justifyContent: "center"
children: [...]
})
]
})
]
})
}
или можно что-то придумать?const SomeComponent = () => {
return Div().width(500).height(500).child(
Div().paddingTop(10).child(
Div().marginLeft(10).justifyContent("center")
).child(
...
)
).child(
...
)
)
но это не особо удобно и слегка непривычно и хотелось бы узнать можно ли что-то придумать с объектными литераламиM
К
К
M
// без коструктора
class Point {
x: i32
y: i32
}
function foo(pt: Point): void {
}
foo({ x: 1, y: 2 }) // то так можно
M
Б
M
class Point {
x: i32
y: i32
}M
Б
Б

К