Closed ianzone closed 3 days ago
The issue you're encountering is related to a change in the order of Hooks called by a component in your React application, specifically within the List
component. This can lead to bugs and errors if not addressed. The error message suggests that the order of Hooks is inconsistent between renders, which violates the Rules of Hooks in React.
Here are some steps you can take to troubleshoot and resolve this issue:
Check the Component Logic: Ensure that the logic within your component does not conditionally call Hooks. Hooks should be called in the same order on every render. Avoid placing Hooks inside loops, conditions, or nested functions.
Review the Component Stack: The error stack trace provides a list of components involved in the rendering process. Start by examining the RawList
and OptionList2
components, as they are mentioned in the stack trace. Look for any conditional logic that might affect the order of Hook calls.
Update Dependencies: Ensure that all dependencies, including React and Ant Design, are up to date. Sometimes, bugs in libraries can cause unexpected behavior.
Simplify the Component: If possible, try to simplify the component to isolate the issue. Remove parts of the component incrementally to see if the error persists, which can help identify the problematic code.
Consult the Documentation: Review the Rules of Hooks to ensure compliance with best practices.
If you have already checked these aspects and the issue persists, it might be helpful to share a minimal reproducible example or consult the community for further assistance.
render props 需要返回 func render。不是提供一个 React Component,React 就会自动当成 Component 来渲染的:
-- optionRender={CountryRender}
++ optionRender={props => <CountryRender {...props} />}
Reproduction link
https://github.com/ianzone/antd-bug
Steps to reproduce
What is expected?
控制台不报错
What is actually happening?