When I try to render Consumer, flow show next error:
[flow] Cannot create
SidebarContextConsumer
element because propertychangeOpenState
is missing in undefined [1] in the first argument of propertychildren
. (References: [1])
Here my code:
// @flow
import React, { createContext } from 'react';
import type { Context, ProviderProps } from './Sidebar.types';
const SidebarContext = createContext();
export const SidebarContextConsumer = SidebarContext.Consumer;
/* eslint-disable react/no-unused-state */
export class SidebarContextProvider extends React.Component<ProviderProps, Context> {
state = {
dynamic: false,
open: false,
transition: false,
changeDynamicMode: (dynamic: boolean) => {
this.setState({
dynamic,
open: false,
transition: false,
});
},
changeOpenState: (open: boolean, transition: boolean = true) => {
this.setState({ open, transition });
},
};
render() {
const { children } = this.props;
return (
<SidebarContext.Provider value={this.state}>
{children}
</SidebarContext.Provider>
);
}
}
/* eslint-enable */
Flow declaration:
export type Context = {
changeDynamicMode: (dynamic: boolean) => void,
changeOpenState: (open: boolean, transition?: boolean) => void,
dynamic: boolean,
open: boolean,
transition: boolean,
};