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

Static methods not being hoisted when using connectors #1191

Closed
wsmd opened this issue Apr 25, 2018 · 2 comments
Closed

Static methods not being hoisted when using connectors #1191

wsmd opened this issue Apr 25, 2018 · 2 comments

Comments

@wsmd
Copy link

wsmd commented Apr 25, 2018

Do you want to request a feature or report a bug?

It could be a bug. It could be a feature request. It could be neither.

Bug: What is the current behavior?

I'm not quite sure If I'm missing something, but I noticed that static methods on components that are connected to the instantsearch context are not being hoisted (copied over) to the composed component.

Here's a simplified example that hopefully illustrates the problem:

import { Component } from 'react';
import { connectStateResults } from 'react-instantsearch/connectors';

class MyComponent extends Component  {
  // this won't be available on the "connected" component
  static doSomething() {}

  componentDidUpdate(prevProps) {}

  render() {}
}

// exporting the connected component as default
export default connectStateResults(MyComponent)

When that component is imported somewhere else in the code, the static method of the composed/wrapped component won't be available:

import MyComponent from './MyComponent';

MyComponent.doSomething //=> undefined (should it be defined?)

Bug: What is the expected behavior?

Should static methods be hoisted/copied to the connected component as well?

Feature: What is your proposed API entry? The new option to add? What is the behavior?

I believe this is a common problem in the React ecosystem, and there are solutions out there to resolve this. For instance, hoist-non-react-statics.

There multiple ways to get around this issue, of course, but I think it would be very convenient to hoist the static methods. What do you think? Are there any downsides to doing so?

What is the version you are using? Always use the latest one before opening a bug issue.

5.0.1

@samouss
Copy link
Collaborator

samouss commented Apr 26, 2018

Indeed we don't support it because nobody ever asked for it (AFAIK). It could be convenient to implement it. I don't think that there is downside to this approach. But most of the time the static methods are used for data fetching since the lib handle this part, I don't have any case in mind where it might be interesting to hoist. Do you have some?

reduxjs/react-redux#276
formatjs/formatjs#196

@samouss samouss removed their assignment Dec 21, 2018
@Haroenv
Copy link
Contributor

Haroenv commented Dec 19, 2022

As React InstantSearch (non-hooks) is no longer our active development branch, we will not work on this.

@Haroenv Haroenv closed this as not planned Won't fix, can't repro, duplicate, stale Dec 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants