1

I created this webpage with create-react-kotlin-app. The xml is different than I'm used to and I'm really struggling using a logo that is in the same directory as index.kt. How can I fix this?

package index

import react.dom.*
import kotlin.browser.*

fun main(args: Array<String>) {

    val rootDiv = document.getElementById("root")

    render(rootDiv) {
        img(src="./logo.jpg"){}
    }
}
3
  • Haven't worked on create-react-kotlin-app recently, but try moving your image in your src/resources folder. (That is even if you have one) Commented Mar 1, 2019 at 7:02
  • Thanks, but didn't work. I didn't have the resources folder, but I created it. Tried src="logo.jpg", src="./resources/logo.jpg" and src="./../resources/logo.jpg" (index.kt is inside folder inside src folder). I also tried moving index.kt out so it's just under the source folder, but couldn't get it to work that way either. Commented Mar 1, 2019 at 9:01
  • try img(src=require("./logo.jpg")){} and reference your image correctly Commented Mar 1, 2019 at 9:15

1 Answer 1

1

Ok, I found a solution simply by taking a look at the create-react-kotlin-app default content, a little awkward.

package index

import react.dom.*
import kotlin.browser.*

@JsModule("src/resources/logo.jpg")
external val logo: dynamic

fun main(args: Array<String>) {

    val rootDiv = document.getElementById("root")

    render(rootDiv) {
        img(src = logo){}
    }
}

Unnecessarily cumbersome if you ask me.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.