I’m trying to find a way to import existing ReactJS components into the ReScript React project:
// Foo.js
import React from 'react'
export default function Foo() {
return (
<h1>Foo</h1>
)
}
// FooWrapper.res
module Foo = {
@react.component @module("./Foo")
external make: unit => React.element = "Foo"
}
@react.component
let make = () => {
<div> <Foo /> </div>
}
I’m getting a webpack error:
ERROR in ./src/Foo.js 5:8
[1] Module parse failed: Unexpected token (5:8)
[1] You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
[1] | export default function Foo() {
[1] | return (
[1] > <h1>Foo</h1>
[1] | )
[1] | }
[1] @ ./src/FooWrapper.bs.js 3:10-26
[1] @ ./src/Main.bs.js
[1] @ ./src/Index.bs.js
Thank you all so much for the help!
Renaming the file to .jsx and configuring the babel loader in webpack helped (also I tried vite - it worked straightaway).
Just leaving this for the record:
// Foo.jsx
import React from 'react'
function Foo() {
return (
<h1>Foo</h1>
)
}
export { Foo }
// FooWrapper.res
module Foo = {
@react.component @module("./Foo.jsx")
external make: unit => React.element = "Foo"
}
@react.component
let make = () => {
<div> <Foo /> </div>
}