Paul N
04/29/2020, 7:46 AM@file:JsModule("react-bootstrap")
@file:JsNonModule
import react.*
@JsName("Dropdown")
external val Dropdown: RClass<DropDownProps>
external interface DropDownProps : RProps {
var bsClass: String?
var componentClass: Any?
var disabled: Boolean?
var dropup: Boolean?
var id: String
var onClose: Function<*>?
var onSelect: Any?
var onToggle: ((isOpen: Boolean) -> Unit)?
var open: Boolean?
var pullRight: Boolean?
var role: String?
}
@JsName("DropdownMenu")
external val DropdownMenu: RClass<DropdownMenuProps>
external interface DropdownMenuProps : RProps {
var labelledBy: dynamic /* String | Number */
var onClose: Function<*>?
var onSelect: Any?
var open: Boolean?
var pullRight: Boolean?
}
@JsName("DropdownItem")
external val DropdownItem: RClass<DropDownItemProps>
external interface DropDownItemProps : RProps {
var eventKey: String
var href: String
}
And here's my component that uses it:
class GroupList: RComponent<GroupListProps, RState>() {
override fun RBuilder.render() {
console.log("Dropdown",Dropdown)
console.log("Dropdown menu is",DropdownMenu)
console.log("Dropdown item",DropdownItem)
Dropdown {
DropdownMenu {
props.groups.forEach {
DropdownItem {
attrs.eventKey = it.id
+it.description
}
}
}
}
}
}
The console log shows DropDownMenu as being undefined (the other two are OK), resulting in my code failing:
DevTools failed to load SourceMap: Could not load content for <chrome-extension://gighmmpiobklfepjocnamgkkbiglidom/include.preload.js.map>: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
GroupList.kt?2322:20 Dropdown {$$typeof: Symbol(react.forward_ref), displayName: "Dropdown", defaultProps: {…}, Toggle: {…}, render: ƒ, …}
GroupList.kt?2322:21 Dropdown menu undefined
GroupList.kt?2322:22 Dropdown item {$$typeof: Symbol(react.forward_ref), displayName: "DropdownItem", defaultProps: {…}, render: ƒ}
react.development.js?6008:315 Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Check the render method of `GroupList`.
in GroupList (created by App)
in div (created by styled.div)
in styled.div (created by App)
in App
Does anyone know what I'm doing wrong ?
Are there any Kotlin wrappers for basic HTML components such as drop downs etc, or is my approach of writing wrappers from scratch (with a little help from Dukat) the only way ?bartosz.malkowski
05/04/2020, 2:15 PMBjörn Mayer
05/06/2020, 9:55 PMforwardRef
is used in Kotlin React?Siddhartha Juluru
05/11/2020, 10:49 PMiari
05/13/2020, 8:26 AMval LoginContext = createContext<LoginContextData>()
I get the following error
When accessing module declarations from UMD, they must be marked by both @JsModule and @JsNonModuleWhat's wrong?
Björn Mayer
05/18/2020, 1:47 PMcloneElement
just broken?
cloneElement<Button.Props>(el) {
// nothing here
}
results in
Cannot define property kotlinHashCodeValue$, object is not extensible
Same result with all the other cloneElement
implementations.
I am trying to clone a ReactElement
and while doing that override some props.Sourabh Rawat
05/25/2020, 5:40 AMstyled
function from material UI but its not working. Can someone provide an example on how to do it, with material UI if possible?Björn Mayer
05/26/2020, 7:01 PMchild(Button::class.rClass, buttonProps) {
attrs {
onClick = this@ButtonGroup::buttonClicked
active = index in state.activeButtons
}
}
This one fails because every property of buttonProps
is readOnlyBjörn Mayer
05/31/2020, 2:45 PMchecked = state.active == true
I do have a custom onChange
handler, which sets the state:
val target = event.target as HTMLInputElement
setState {
active = target.checked
}
When checking the checkbox, react throws this message:
react_devtools_backend.js:6 Warning: A component is changing an uncontrolled input of type checkbox to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component. More info: <https://fb.me/react-controlled-components>
Paul N
06/02/2020, 3:29 PMchristophsturm
06/08/2020, 3:32 PMfrank
06/13/2020, 2:12 PMBig Chungus
06/14/2020, 4:07 PMuseState
hook in pure kotlin? Or does it rely on JS's var
magic?frank
06/15/2020, 5:16 AMchild()
or directly passing my fuctional component but dont work.
class listMsg : RComponent<msgListProps, msgListState>() {
override fun RBuilder.render() {
props.msg.forEachIndexed { index, msg ->
when(msg.type){
"log" -> itemLog //Dont work
else -> li {
attrs.key = index.toString()
div(classes = "receivedMessages") {
span(classes = "filledInitials") {
+getInitials(msg.nickName)
}
span(classes = "chatMessage") {
+msg.msg
}
}
}
}
}
}
}
val itemLog = functionalComponent<itemLogProps>{ props ->
li(classes = "log") {
p {
+props.msg
}
}
}
christophsturm
06/19/2020, 9:36 AMfrank
06/21/2020, 8:44 PMonSendMessageClicked()
function inside of my functionalComponent the elements can't find it and I need to declare it outside.
val chatWindowComponent = functionalComponent<ChatMsgListProps>{ props ->
val (mensajes,setMensajes) = useState(arrayOf<ReactElement>())
div(classes = "chatWindow") {
div {
button(classes = "sendMessageButton") {
+"Send Message"
attrs.type = ButtonType.button
attrs.onClickFunction = onSendMessageClicked()
}
}
}
fun onSendMessageClicked(): (Event) -> Unit {
return {
//Code
}
}
}
The disadvantage of declaring onSendMessageClicked()
outside is that I need to send setState
in all functions that use it. Alternatives to this?
fun onSendMessageClicked(setMsg: RSetState<Array<ReactElement>>): (Event) -> Unit {
return {
//Something(setMsg)
}
}
andylamax
06/30/2020, 10:13 PMexternal interface DumbProps {
var name: String
}
val DumbComp = functionalComponent<DumbProps> {
div { +"Hi, I am ${it.name}" }
}
Then, I would have to create an extension for RBuilder like so
fun RBuilder.DumbComp(props: DumbProps,handler:RHandler<DumbProps>) = child(DumbComp,props,handler)
This makes the usage of functional components and hooks so verbose.
Advice: RBuilder should add a member function to ease use of functional components and hooks like so
class RBuilder{
. . .
operator fun <P : RProps> FunctionalComponent<P>.invoke(
props: P = jsObject(),
handler: RBuilder.(P) -> Unit
) = child(this, props, handler)
. . .
}
So that now, I can just go and call
DumbComp {
attrs.name = "Andy"
}
Joost Klitsie
07/08/2020, 11:44 AMfun main(args: Array<String>) {
render(document.getElementById("root")) {
child(App)
}
}
val SomeContext = createContext(1)
val App = functionalComponent<RProps> {
SomeContext.Provider(5) {
typographyH1 {
+useContext(SomeContext).toString() // Actually shows '1'
}
}
}
eloew
07/09/2020, 10:28 AMimplementation(npm("react-router-dom", "4.3.1"))
implementation(npm("@jetbrains/kotlin-react-router-dom", "4.3.1-pre.91"))
It builds but gets the error when I run. Noticed that build/js/node_modules does not have kotlin-react-router-dom
I have a sample project at: https://github.com/eloew/KotlinReactRoutewillyrs
07/10/2020, 4:12 PMSiddhartha Juluru
07/13/2020, 10:55 PMRob Murdock
07/15/2020, 7:34 PMepabst
08/01/2020, 4:55 AMgvnavin
08/03/2020, 2:06 PMgvnavin
08/08/2020, 6:31 AMbnorm
08/23/2020, 6:02 PMsample
directory, and mess around if you would like to try it out. Feel free to open issues with suggestions and any problems you find!bnorm
08/24/2020, 11:52 PMmkosm
08/26/2020, 3:52 PMstyledDiv
is an extension to RBuilder
, so I'm not sure how it could be used outside of `render()`: https://styled-components.com/docs/basics#define-styled-components-outside-of-the-render-methodJoost Klitsie
09/20/2020, 7:49 AMaudio {
attrs {
src="sounds/time.mp3"
}
}
How can I run play() on it? 🙂Joost Klitsie
09/28/2020, 3:07 PMfun <T> CommonAttributeGroupFacade.onClick(argument: T, func: (T) -> Unit) {
onClickFunction = useCallback(
callback = {
func(argument)
},
dependencies = arrayOf(argument)
)
}
var CommonAttributeGroupFacade.onClick: () -> Unit
get() = throw UnsupportedOperationException("You can't read variable onClick")
set(newValue) {
onClickFunction = useCallback(
callback = {
newValue()
},
dependencies = emptyArray()
)
}
var CommonAttributeGroupFacade.onTextChange: (String) -> Unit
get() = throw UnsupportedOperationException("You can't read variable onChange")
set(newValue) {
onChangeFunction = useCallback(
callback = { event: Event ->
newValue(event.target.asDynamic().value as String)
},
dependencies = emptyArray()
)
}
The only problem I have is: if I have a list where I can add/remove items, where the list items use one of these (for example onclick), I will get (logically) errors about not having the same amount of hooks when I add/remove list items. To solve that problem, I created a useList method that wraps the list in a functional component and gets recreated on data changes:
fun <T : BaseListItem> RBuilder.useList(
list: List<T>,
vararg classMap: Pair<ListStyle, String>,
block: ListElementBuilder<UL, ListProps>.(List<T>) -> Unit
) {
useCallback(
functionalComponent<RProps> { list(classMap = *classMap, block = { block(list) }) },
arrayOf(list)
).also { child(it) }
}
Which gives the issue of having a sluggish list during a lot of interactions (for example typing into a list element).Joost Klitsie
09/28/2020, 3:07 PMfun <T> CommonAttributeGroupFacade.onClick(argument: T, func: (T) -> Unit) {
onClickFunction = useCallback(
callback = {
func(argument)
},
dependencies = arrayOf(argument)
)
}
var CommonAttributeGroupFacade.onClick: () -> Unit
get() = throw UnsupportedOperationException("You can't read variable onClick")
set(newValue) {
onClickFunction = useCallback(
callback = {
newValue()
},
dependencies = emptyArray()
)
}
var CommonAttributeGroupFacade.onTextChange: (String) -> Unit
get() = throw UnsupportedOperationException("You can't read variable onChange")
set(newValue) {
onChangeFunction = useCallback(
callback = { event: Event ->
newValue(event.target.asDynamic().value as String)
},
dependencies = emptyArray()
)
}
The only problem I have is: if I have a list where I can add/remove items, where the list items use one of these (for example onclick), I will get (logically) errors about not having the same amount of hooks when I add/remove list items. To solve that problem, I created a useList method that wraps the list in a functional component and gets recreated on data changes:
fun <T : BaseListItem> RBuilder.useList(
list: List<T>,
vararg classMap: Pair<ListStyle, String>,
block: ListElementBuilder<UL, ListProps>.(List<T>) -> Unit
) {
useCallback(
functionalComponent<RProps> { list(classMap = *classMap, block = { block(list) }) },
arrayOf(list)
).also { child(it) }
}
Which gives the issue of having a sluggish list during a lot of interactions (for example typing into a list element).araqnid
09/28/2020, 6:13 PM