withTheme does not forward ref
See original GitHub issueDescription
The withTheme
HOC is not forwarding it’s ref. Therefore it is e.g. not possible to submit a form programmatically. React.forwardRef is available from 16.3.0, an implementation would look like this:
import React, { forwardRef } from "react";
import PropTypes from "prop-types";
import Form from "./";
function withTheme(themeProps) {
return forwardRef(({ fields, widgets, ...directProps }, ref) => (
<Form
{...themeProps}
{...directProps}
fields={{ ...themeProps.fields, ...fields }}
widgets={{ ...themeProps.widgets, ...widgets }}
ref={ref}
/>
));
}
withTheme.propTypes = {
widgets: PropTypes.object,
fields: PropTypes.object,
};
export default withTheme;
For now I will use my own HOC instead of withTheme. Please fix this as soon as you bump the React peer version. I will happily provide an PR then, testcase also kinda done:
it('should forward the ref', () => {
let ref = undefined;
const schema = {};
const uiSchema = {};
createComponent(withTheme({ ref: (form) => ref = form }), {
schema,
uiSchema,
});
expect(ref.submit).to.exist();
});
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Get ref from connected redux component withStyles
In TodoList , I'm using withStyles to add a blue border around the todo list to show that withStyles is working, and I'm...
Read more >Forwarding Refs - React
Ref forwarding is not limited to DOM components. You can forward refs to class component instances, too. Note for component library maintainers. When...
Read more >forward-ref and theme from styled wrapper - CodeSandbox
forward -ref and theme from styled wrapper. Copied source from https://github.com/styled-components/styled-components#basic.
Read more >styled() - MUI System
It uses MUI's default theme if no theme is available in React context. ... bool [optional]): Indicates whether the prop should be forwarded...
Read more >React Ts Forward Ref With Styled Components - StackBlitz
import React, { useRef, useEffect, useState }. from "react";. import { render } from "react-dom";. import { Foo } from "./foo";. import "./style.css";....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@jorisw pr is opened
Hey @andrew-oreshko , I also encountered this issue. For now, and as a temporary fix, I created my own withTheme HOC using the code provided by @zepatrik. Beware that this will only work if your project uses react version
16.3.0
or higher.