The render() method is the only required method in a class component. It is called after static getDerivedStateFromProps and before componentDidMount. It is used to render the UI of the component.
React elements. Typically created via JSX. For example, <div /> and <MyComponent /> are React elements that instruct React to render a DOM node, or another user-defined component, respectively.
Arrays and fragments. Let you return multiple elements from render. See the documentation on fragments for more details.
Portals. Let you render children into a different DOM subtree. See the documentation on portals for more details.
String and numbers. These are rendered as text nodes in the DOM.
Booleans or null or undefined. Render nothing. (Mostly exists to support return test && <Child /> pattern, where test is boolean).
render() will not be invoked if shouldComponentUpdate() returns false
The render() function should be pure, meaning that it does not modify the component state, it returns the same result each time it’s invoked, and it does not directly interact with the browser.
If you need to interact with the browser, perform your work in componentDidMount() or the other lifecycle methods instead. Keeping render() pure makes components easier to think about.
If you create a class component with a render method that returns <div>Hello</div>, what will the user see when the component mounts?
What happens if the render method returns undefined or null?
How would you conditionally render a loading spinner inside the render method based on a prop called isLoading?
You added a console.log inside render and noticed it runs multiple times after a state update. Why does that happen and how would you minimize unnecessary renders?
A teammate changed a component's render to map over an array but forgot to provide a key. The UI shows a warning and behaves oddly. Explain the issue and how to fix it.
During a feature rollout, the component's render throws an error when a required prop is missing. How would you guard against that without using try/catch?
Our dashboard renders thousands of rows using a class component's render. Performance is lagging. What strategies would you employ at the render level to improve performance?
We need to support server‑side rendering for a component that uses lifecycle methods. How does the render method behave on the server vs client, and what adjustments are required?
Explain how you would refactor a deeply nested render method that contains many conditional branches to improve readability and maintainability.
We are migrating a large codebase from class components to functional components with hooks. How would you approach the transition of render logic, and what patterns would you enforce to keep behavior consistent?
Multiple teams share a UI library with components that have complex render methods. How would you establish guidelines or tooling to ensure render performance and avoid regressions across releases?
Our product needs to support theming and feature flags that affect rendering at many levels. Design an architecture that allows render methods to react to these concerns without scattering conditional logic throughout the codebase.