Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Consider supporting any React versions by parameterizing React lib #17

Closed
zaim opened this issue Sep 17, 2015 · 4 comments
Closed

Consider supporting any React versions by parameterizing React lib #17

zaim opened this issue Sep 17, 2015 · 4 comments

Comments

@zaim
Copy link

zaim commented Sep 17, 2015

Hi.

Since tcomb-react is using a very small (and stable?) subset of the React API (only ReactElement and ReactNode), it might be preferable to not have a hard dependency on React and a specific version.

Instead, create the t.React* types dynamically by accepting a React object.

Usage would be something like:

import React from 'react'
import { props, t } from 'tcomb-react'

t.ReactElement // undefined

t.addReactTypes(React)

@props({
  children: t.ReactElement // ok!
})
class MyComponent extends React.Component {

  render() {
    return (
      <div>
        {this.props.children}
      </div>
    );
  }

}

This might be a breaking change since t.React* types won't be available at first import.

Another approach is to wrap your require('react') with a try catch.

Or is this too complicated? It's just that I wanted to try this with React 0.14.0-rc1 but cant... :)

@gcanti
Copy link
Owner

gcanti commented Sep 17, 2015

Hi @zaim,
Actually tcomb-react should be compatible with react@0.14.0-rc1 as the only API used is React.isValidElement (ReactElement and ReactNode are tcomb types).

https://github.com/gcanti/tcomb-react/releases/tag/v0.8.9

@zaim
Copy link
Author

zaim commented Sep 17, 2015

Hmmm... I'm still getting 2 copies of React in node_modules, that is:

  1. The "main" node_modules/react (0.14.0-rc1)
  2. The one tcomb-react uses, node_modules/tcomb-react/node_modules/react (0.13.3)

Browserifying would include both copies, I think.

I think it's because 0.14.0-rc1 (anything with -prerelease) does not satisfy >=0.13.0 which is what's in your package.json.

So basically, my suggestion would make tcomb-react compatible with any and every future React releases, including pre-releases (as long as React.isValidElement is not deprecated 😉)

@gcanti
Copy link
Owner

gcanti commented Sep 17, 2015

my suggestion would make tcomb-react compatible with any and every future React releases, including pre-releases (as long as React.isValidElement is not deprecated 😉)

Indeed, I thought that >=0.13.0 would be enough but it doesn't work with release candidates.
Related npm/npm#8854

@gcanti
Copy link
Owner

gcanti commented Dec 17, 2015

Closing as per React v0.14

@gcanti gcanti closed this as completed Dec 17, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants