fable-compiler / fable-react

Fable bindings and helpers for React and React Native
MIT License
273 stars 67 forks source link

Can't reference React in Fable #214

Closed Montana closed 3 years ago

Montana commented 3 years ago

I am trying to write a React component in F# with Fable, and I'm having trouble referencing the necessary libraries. The compile errors I'm getting are as follows:

The namespace 'React' is not defined. ('open' statements). The type PureStatelessComponent is not defined.

Here is my code currently, seen a similar thread, but the solution offered in that did not work:

module ContactInfoComponent

open Fable.Core
open Fable.Core.JsInterop
open Fable.Import
open Fable.Import.Browser
open Fable.React
open Fable.React.Helpers

type ContactInfoProps = {
    Name : string
}

type ContactInfoComponent(initialProps) = 
    inherit PureStatelessComponent<ContactInfoProps>(initialProps)
    override this.render() = 

        div [] [ 
            str "Name: "
            input [Type "text" Id "txtName"]
        ]

I appreciate any help, thank you.

-Montana Mendy

alfonsogarciacaro commented 3 years ago

Not sure if that's the problem, but please make sure you're using the latest library version. Looking at the open statements it seems you're using Fable.Import.Browser which is deprecated, please use Fable.Browser.Dom instead (latest Fable.React already includes it as a dependency).

// Access DOM global values like window, document, etc
open Browser

// Access DOM types likes KeyboardEvent, etc
open Browser.Types

If this doesn't help can you please tell us:

Montana commented 3 years ago

Tried:

Fable.Browser.Dom

Worked! Seems like I've ran into the deprecated issue before - gotta keep on it. Thank you @alfonsogarciacaro!