hello im a fp noob and just wanted to dip my toes in using reactjs with purescript. below i have a snippet of a react component inside another react component. Im trying to convert this into purescript but don’t know how to do it. I have both components coming in through FFI which seems to be working fine. I also took a look at the docs and reccommended tutorials but cant find how to do it but there seems to be a function called reactcomponentWithChildren that i have no idea how to use. any help is appreciated.
<MapContainer center={[51.505, -0.09]} zoom={13} scrollWheelZoom={false}
style={{ height:"400px",backgroundColor:"red",marginTop:"80px", marginBottom:'90px'
}}>
<TileLayer
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
<Marker position={[51.505, -0.09]}>
<Popup>
A pretty CSS3 popup. <br /> Easily customizable.
</Popup>
</Marker>
</MapContainer>
module Foreign.LeafletMap
( marker
, popup
, tileLayer
)
where
import Data.Maybe (Maybe(..))
import React.Basic.Hooks (ReactComponent)
foreign import leafletMap
:: ReactComponent
{ center :: Array Number
, zoom :: Int
, scrollWheelZoom :: Boolean
}
foreign import tileLayer :: ReactComponent
{
attribution :: String
, url :: String
}
module Main
( main
, mkRandomBox
)
where
import Prelude
import Data.Maybe (Maybe(..))
import Effect (Effect)
import Effect.Exception (throw)
import Effect.Random (randomInt)
import Foreign.ReactPlayer (reactPlayer)
import Foreign.LeafletMap (leafletMap, tileLayer, marker, popup)
import React.Basic.DOM (css)
import React.Basic.DOM as R
import React.Basic.DOM.Client (createRoot, renderRoot)
import React.Basic.Events (handler_)
import React.Basic.Hooks (Component, component, element, useState', (/\), reactComponentWithChildren)
import React.Basic.Hooks as React
import Web.DOM.NonElementParentNode (getElementById)
import Web.HTML (window)
import Web.HTML.HTMLDocument (toNonElementParentNode)
import Web.HTML.Window (document)-- | Find the element with `app` id, that we declared in `index.html`.
-- | Create and render a component tree into this element,
-- | Or crash in case we messed up during the setup.
main :: Effect Unit
main = do
doc <- document =<< window
container <- getElementById "app" $ toNonElementParentNode doc
case container of
Nothing -> throw "Could not find container element"
Just c -> do
leaflet <- reactComponentWithChildren "Leaflet" \_ -> React.do
pure $ element leafletMap
{ center: [100.0, 100.0]
, scrollWheelZoom: false
, zoom: 50
-- , style: css { height:"400px"
-- , backgroundColor:"red"
-- , marginTop:"80px"
-- , marginBottom:"90px"
-- },
-- , children: [
-- element tileLayer { attribution: "© <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors"
-- , url:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
-- }
-- ]
}
reactRoot <- createRoot c
renderRoot reactRoot (leaflet )