-
Notifications
You must be signed in to change notification settings - Fork 4k
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
FormInput: Support for defaultProps will be removed [v3] #4426
Comments
👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you've completed all the fields in the issue template so we can best help. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can. |
FYI It's not only about Semantic-UI-React/src/modules/Search/Search.js Lines 682 to 688 in 7d3e162
Semantic-UI-React/src/addons/Radio/Radio.js Lines 36 to 38 in 7d3e162
Semantic-UI-React/src/views/Feed/FeedUser.js Lines 38 to 40 in 7d3e162
Semantic-UI-React/src/views/Feed/FeedLike.js Lines 34 to 36 in 7d3e162
Semantic-UI-React/src/elements/Icon/IconGroup.js Lines 43 to 45 in 7d3e162
Actions
|
Anyone know of a way to suppress that specific warning or some react version to rollback? Or anyone working on a PR? This is soooo annoying! |
Nope, this issue waits for the hero 🦸 |
I'll try to find some time to do it. Meanwhile... |
We experience the warning with these components
|
@layershifter I've attempted to start work on this. On my very first attempt at updating MessageItem, removing the defaultProps and changing the function to look like const MessageItem = React.forwardRef(function (props, ref) {
const { children, className, content, as="li" } = props did not seem to actually set the
Any advice here would be appreciated. |
So, this does work. Is this method acceptable? ~ const MessageItem = React.forwardRef(function (passedProps, ref) {
+ const defaultProps = { as: 'li' }
+ const props = { ...defaultProps, ...passedProps }
const { children, className, content } = props |
Noting here that removal of if (alwaysPresent || (Component.defaultProps && Component.defaultProps[propKey])) {
it(`has default ${name} when not defined`, () => {
wrapper = mount(React.createElement(Component, requiredProps))
wrapper.should.have.descendants(ShorthandComponent)
})
} (Link to code in test/specs/commonTests/implementsShorthandProp.js) Since these testcases are dynamically generated, it's going to be important that, if reasonable, the number of tests asserted is the same before and after these changes. Failing to generate a testcase would result in a silent failure. |
@joequery thanks for looking to it and sorry for delay in the reply. My proposal is to replace // src/collections/Message/MessageItem.js
- const ElementType = getElementType(MessageItem, props)
- const ElementType = getComponentType(props, { defaultAs: 'li' }) // src/lib/index.js
+export getComponentType from './getComponentType'
export getElementType from './getElementType' // src/lib/getComponentType.js
/**
* Returns a createElement() type based on the props of the Component.
* Useful for calculating what type a component should render as.
*
* @param {object} props A ReactElement props object
* @param {object} [options={}]
* @param {function} [options.defaultAs] A default element type.
* @param {function} [options.getDefault] A function that returns a default element type.
* @returns {string|function} A ReactElement type
*/
function getComponentType(props, options = {}) {
const { defaultAs, getDefault } = options
// ----------------------------------------
// user defined "as" element type
if (props.as && props.as !== defaultAs) return props.as
// ----------------------------------------
// computed default element type
if (getDefault) {
const computedDefault = getDefault()
if (computedDefault) return computedDefault
}
// ----------------------------------------
// infer anchor links
if (props.href) return 'a'
// ----------------------------------------
// use defaultProp or 'div'
return defaultAs || 'div'
}
export default getComponentType in the end, |
Released in |
SideBar component still gives the defaultProps message on 3.0.0-beta.2 EventListener2: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead |
Hello, I am using the library in version "semantic-ui-css": "^2.5.0", and "semantic-ui-react": "^2.1.4", along with react 18 and next 13 , and I am having the following warning or error, I searched but found no solution, would not be compatible with the version I use?
The text was updated successfully, but these errors were encountered: