-
Notifications
You must be signed in to change notification settings - Fork 347
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
Cannot use memoCustomCompareProps #422
Comments
The same is true of |
Can you give an example of how context was giving you trouble? It can work fine if you drop out of JSX with something like
Or if you copy over the make + makeProps directly from provider. Looking at |
@rickyvetter do you know if the current context API is final? It is a bit cumbersome and not obvious right now. Since it is not documented yet and was not mentioned in the release notes I guess it is still a work in process. These two options work right now:
and
but thats kind of "manual", I was expecting something similar to:
implemented like:
or maybe for the whole context bundle to be created with a functor (resulting in a module with Consumer/Provider submodules) |
Functor bundling everything: module type CONFIG = {
type t;
let initialValue: t;
};
module Make = (Config: CONFIG) => {
type t = Config.t;
let context = React.createContext(Config.initialValue);
let use = () => React.useContext(context);
module Provider = {
[@react.component]
let make = {
let provider = React.Context.provider(context);
(~value=Config.initialValue, ~children) => {
React.createElement(
provider,
{"value": value, "children": children},
);
};
};
};
module Consumer = {
[@react.component]
let make = (~children) => <> {children(use())} </>;
};
}; Example module MyContext =
Context.Make({
type t = string;
let initialValue = "hello";
}); then <MyContext.Provider value="Bye">
<MyContext.Consumer>
{value => s(value)}
</MyContext.Consumer>
</MyContext.Provider> and also let myContext = MyContext.use();
// or
let myContext = React.useContext(MyContext.context); |
I've found a workaround for this, which is so simple that it suggests changing this in let memo = React.memoCustomCompareProps(_, (_, _) => true);
[@react.component]
let make = memo(() => <View />); EDIT: I've had a look at the ppx code and I'm afraid it's beyond me! |
Would be good to find a fix for this! |
Attempting to use
React.memoCustomCompareProps
throws the following compiler error:The text was updated successfully, but these errors were encountered: