r/purescript • u/tmountain • Dec 13 '18
Problem Rendering non-React-Basic Component
Hi, I'm trying to work through rendering third-party React components alongside components I'm creating in react-basic, and I'm running into a problem.
I'm using react-select as my third-party component.
"use strict";
const Select = require('react-select').Select;
exports.reactSelect = function() {
return Select;
}Foreign import declaration:
module Components.ReactSelect where
import React.Basic (ReactComponent)
type Fields = Array { value :: String, label :: String }
type Props = {options :: Fields}
foreign import reactSelect :: ReactComponent PropsCreating the component. I know it's not a "label". This is crappy debug code, so please ignore that.
newLabel :: {} -> JSX
newLabel = makeStateless newComponent
\props -> element reactSelect
{options: [ { value: "foo", label: "Foo" },
{ value: "bar", label: "Bar" }]}Then, attempting to render.
app :: JSX
app = unit # makeStateless component _ ->
R.div_
[ R.h1_ [ R.text "Hello Derp" ]
, toggle { initialValue: true }
, toggle { initialValue: false }
, redLabel { label: "Whoa!" }
, newLabel { }
]When I add newLabel (the third-party component), I get nothing back (screen goes white). Inspecting the JS gives:
Uncaught Error: Component(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.
Also, here's a react-select example if that's helpful.
import React, { Component } from 'react'
import Select from 'react-select'
const options = [
{ value: 'chocolate', label: 'Chocolate' },
{ value: 'strawberry', label: 'Strawberry' },
{ value: 'vanilla', label: 'Vanilla' }
]
const MyComponent = () => (
<Select options={options} />
)I can provide the full code if that's helpful. Thanks!
View all comments
1
u/jusrin Dec 14 '18
Your FFI is an actual function?
Is what you have now. You can remove the function call and it should work if the Select is an actual ReactComponent