Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

Impure lifecycle HOC #735

Open
suzdalnitski opened this issue Aug 30, 2018 · 1 comment
Open

Impure lifecycle HOC #735

suzdalnitski opened this issue Aug 30, 2018 · 1 comment

Comments

@suzdalnitski
Copy link

The way lifecycle is currently implemented is that it requires the use of this within the lifecycle methods. This goes against the principles of functional programming and introduces impurity into the HOCs.

I propose to introduce alternative lifecycle HOCs that are pure and provide the props/setState as arguments.

Before:

const withFetch = lifecycle({
  componentDidMount() {
    fetchPosts(this.props.username).then(posts => {
      this.setState({ posts });
    })
  }
});

After:

const withFetch = withComponentDidMount(
  ({username}, setState) => {
    const posts = await fetchPosts(username);
    setState({ posts });
  }
); 

Is this something that would be welcomed in a Pull Request? Thanks.

@istarkov
Copy link
Contributor

see https://github.com/deepsweet/hocs/blob/master/readme.md here lifecycle will possibly be deprecated at all

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