Skip to content

setState callback called with null instead of undefined #10100

@gwmccull

Description

@gwmccull

Do you want to request a feature or report a bug?
bug

What is the current behavior?
In React v16, the callback function that is an optional parameter to the setState function is called and passed a value of null. Previously, in React v15, the function was called with a value of undefined. This change breaks the default parameters feature of JavaScript.

I discovered this behavior while working on a React Native project (hence the example using View & Text).

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar (template: https://jsfiddle.net/84v837e9/).

import React, {
	Component,
} from 'react';

export default class MyComp extends Component {
	componentDidMount() {
		this.setState({}, (val) => console.log(val))
	}

	render() {
		return (
			<View>
				<Text>{this.props.climbs}</Text>
			</View>
		);
	}
}

What is the expected behavior?
The callback function will be called with undefined

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
Broken behavior was observed in React 16 alpha 12 and React Native 0.45.1.

I replicated the issue in React 15.4.1 and React Native 0.40.0 and it was working as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions