Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnecessary dependencies on package.json when installing #5

Closed
guilhermebruzzi opened this issue Oct 17, 2017 · 6 comments
Closed

Unnecessary dependencies on package.json when installing #5

guilhermebruzzi opened this issue Oct 17, 2017 · 6 comments

Comments

@guilhermebruzzi
Copy link

guilhermebruzzi commented Oct 17, 2017

Even thought most of these dependencies were on my devDependencies, yarn add it to yarn.lock and node_modules:

"dependencies": {
    "babel-core": "^6.25.0",
    "babel-loader": "^7.1.1",
    "babel-runtime": "^6.23.0",
    "prop-types": "^15.5.10",
    "webpack": "^3.3.0"
  },

I believe most of those dependencies should be a devDependency and prop-types is not a dependency, since you use flow

@guilhermebruzzi
Copy link
Author

But I just realized that to remove these as a dependency, than you should generate a compiled version (without Flow), right?

@bvaughn
Copy link
Owner

bvaughn commented Oct 20, 2017

Whoops! I probably just forked another OSS project I had to create this one and wasn't careful about cleaning up dependencies. That or I forgot the --dev flag when yarn adding some.

Either way, sorry. I'll tidy up before the next release.

@bvaughn
Copy link
Owner

bvaughn commented Oct 20, 2017

Should be fixed in 1.1.0!

@bvaughn bvaughn closed this as completed Oct 20, 2017
@guilhermebruzzi
Copy link
Author

guilhermebruzzi commented Oct 20, 2017

@bvaughn Nice! :D I've copied the component code without Flow (using prop-types instead) to my project, so no extra dependencies were needed, the main part is small actually:

import React, { Component } from 'react'
import PropTypes from 'prop-types'

class ErrorBoundary extends Component {
  constructor(props, context) {
    super(props, context)

    this.state = {
      error: null,
      info: null,
    }
  }

  componentDidCatch(error, info) {
    const { onError } = this.props

    if (typeof onError === 'function') {
      try {
        onError(error, info ? info.componentStack : '')
      } catch (error) {}
    }

    this.setState({ error, info })
  }

  render() {
    const { children, FallbackComponent } = this.props
    const { error, info } = this.state

    if (error !== null) {
      return (
        <FallbackComponent
          componentStack={info ? info.componentStack : ''}
          error={error}
        />
      )
    }

    return children
  }
}

ErrorBoundary.propTypes = {
  children: PropTypes.any,
  FallbackComponent: PropTypes.any.isRequired,
  onError: PropTypes.func,
}

export default ErrorBoundary

@bvaughn
Copy link
Owner

bvaughn commented Oct 20, 2017

Will prob do a follow-up release to generate prop-types from the Flow types for people who prefer to use them. Although I guess there's not much motivation if you just embed the tiny component 😄

@guilhermebruzzi
Copy link
Author

guilhermebruzzi commented Oct 20, 2017

@bvaughn oh but you should definitely do it anyway, not all people use Flow. Thanks for the great work, this React 16 componentDidCatch feature that this component helps to use is very Nice! :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants