react-component / react-component/menu
problems in extending the component
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 701
- Forks
- 266
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 3
Description
I am developing a ui intensitve project.
My strategy is
- in the first stage, I will use existing react component functionalities by extending them so that I can focus on main functionality I am developing. I recently learn that rc-compoents are among core components of ant-design. I thought they should have worked well after being inherited by cutomer components.
for example
class Switch extends RcSwitch {
}
Switch.propTypes = ...
- in the second stage, I will replace them by my own twisted version one by one.
I found that when I extend them, for example, rc-menu, the props will not be passed correctly from parent to children. How should I implement rc-components?
In antd , they did that in this manner
class SubMenu extends React.Component<any, any> {
static contextTypes = {
antdMenuTheme: PropTypes.string,
};
// fix issue:https://github.com/ant-design/ant-design/issues/8666
static isSubMenu = 1;
private subMenu: any;
onKeyDown = (e: React.MouseEvent<HTMLElement>) => {
this.subMenu.onKeyDown(e);
}
saveSubMenu = (subMenu: any) => {
this.subMenu = subMenu;
}
render() {
const { rootPrefixCls, className } = this.props;
const theme = this.context.antdMenuTheme;
return (
<RcSubMenu
{...this.props}
ref={this.saveSubMenu}
popupClassName={classNames(`${rootPrefixCls}-${theme}`, className)}
/>
);
}
}
export default SubMenu;
Clearly, I can employ flow-typed in es6 to do the exactly the same thing. But I won't because I think there is some problem in the original implementation so that I cannot simply "extend" it and follow the api provided by documentation. I pursue a nice method to do that without looking into the source code of "rc" series of components.
Could any developers give me some hint?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the public extension APIs for rc-menu, RcSwitch, and RcSubMenu, comparing them with the antd SubMenu example shown in the issue. Reproduce the reported parent-to-child props problem with a minimal derived component; done means identifying whether inheritance is supported and documenting a concrete implementation or limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100