Mike Dawson
12/22/2022, 3:25 PM@file:JsModule("react-easy-sort")
@file:JsNonModule
package com.ustadmobile.view.components
import react.PropsWithChildren
import react.ReactNode
external interface SortableListProps: PropsWithChildren {
var onSortEnd: (oldIndex: Int, newIndex: Int) -> Unit
var draggedItemClassName: String?
var lockAxis: String?
var allowDrag: Boolean
}
external val SortableList: react.FC<SortableListProps>
//See <https://betterprogramming.pub/understanding-the-difference-between-named-and-default-exports-in-react-2d253ca9fc22>
external interface ItemProps: PropsWithChildren {
override var children: ReactNode?
}
external val SortableItem: react.FC<ItemProps>
If I use only SortableList or SortableItem, the components seem to be found as expected. When I try to use both together, I get an exception "You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.".
Is there a procedure that can allow making a wrapper for typescript where there is both a default export and named exports?turansky
12/22/2022, 10:40 PM@JsName("default")
external val SortableList: react.FC<SortableListProps>
Mike Dawson
12/23/2022, 7:20 AMexport const SortableItem = ({ children }: ItemProps)
I had tried using PropsWithChildren as follows:
external interface ItemProps: PropsWithChildren {
override var children: ReactNode?
}
SortableItem {
+ "One"
}
That resulted in an exception being thrown when it tried to access children, even when there were children in the node.
Using a "normal" property, and then setting it like this worked:
external interface ItemProps: Props {
var children: ReactNode?
}
external val SortableItem: react.FC<ItemProps>
SortableItem {
children = div.create {
+ "One"
}
}
ItemProps now looks the same as PropsWithChildren, Is props.children supposed to be set somehow based on the children of the component?
I think I can make this wrapper cooperate now, thanks! I'll share a Github Gist once it's all in order.Mike Dawson
12/23/2022, 10:27 AMturansky
12/23/2022, 2:31 PMexternal interface ItemProps: Props {
var children: ReactElement?
}
?Mike Dawson
12/23/2022, 2:32 PMtype ItemProps = { children: React.ReactElement }
turansky
12/23/2022, 2:33 PMPropsWithChildren
will work in such caseturansky
12/23/2022, 2:34 PMSortableItem {
div {
+ "One"
}
}
Mike Dawson
12/23/2022, 2:34 PMturansky
12/23/2022, 2:35 PMturansky
12/23/2022, 2:36 PMPropsWithChildren
in such casesMike Dawson
12/23/2022, 2:36 PMMike Dawson
12/23/2022, 2:39 PMMike Dawson
12/23/2022, 2:39 PMturansky
12/23/2022, 2:42 PMPropsWithChildren
- isn’t strict solution right now, but it’s right directionMike Dawson
12/23/2022, 2:44 PM