# Functional Stateless Components in React

DevFeed: [Functional Stateless Components in React](<https://devfeed.tech/articles/functional-stateless-components-in-react-52483.md>)

Original publisher: [Read original article](<http://www.jackfranklin.co.uk/blog/functional-stateless-components-react/>)

Published: 2017-03-07T00:00:00Z

Content type: article

Language: en

Sources: [Jack Franklin](<https://devfeed.tech/sources/jack-franklin.md>)

Topics: [React](<https://devfeed.tech/topics/react.md>), [stateless](<https://devfeed.tech/topics/stateless.md>), [Functional programming](<https://devfeed.tech/topics/functional-programming.md>), [ECMAScript](<https://devfeed.tech/topics/ecmascript.md>)

Tags: [arrow](<https://devfeed.tech/tags/arrow.md>), [components](<https://devfeed.tech/tags/components.md>), [destructuring](<https://devfeed.tech/tags/destructuring.md>), [es2015](<https://devfeed.tech/tags/es2015.md>), [function](<https://devfeed.tech/tags/function.md>), [functional](<https://devfeed.tech/tags/functional.md>), [react](<https://devfeed.tech/tags/react.md>), [react-component](<https://devfeed.tech/tags/react-component.md>), [simplicity](<https://devfeed.tech/tags/simplicity.md>), [state](<https://devfeed.tech/tags/state.md>), [stateful](<https://devfeed.tech/tags/stateful.md>), [stateless](<https://devfeed.tech/tags/stateless.md>), [syntax](<https://devfeed.tech/tags/syntax.md>)

## AI overview

React 0.14 functional stateless components (FSCs) express presentational UI as props in and rendered output out, often in a concise function or arrow function. The article recommends them for simple rendering components: their form signals the absence of state and lifecycle logic, and they are easier to test by passing props and checking output. Use a class component when lifecycle methods or multiple event handlers are needed, or when frequent state changes are justified; converting an FSC to a stateful component takes more work, which the author sees as a prompt to reconsider adding state. FSCs can define inline event handlers, propTypes, defaultProps, and context. Inline handlers are recreated on rerender and may matter in performance critical cases, though the article says most applications will not notice. It describes possible future React optimizations but explicitly says FSCs currently have no performance advantage.

## Source excerpt

What are functional, stateless components? React 0.14 introduced functional, stateless components as a way to define React components as a function, rather than as an ES2015 class or via React.createClass. Prior to React 0.14, writing a presentational component (that is, one that just renders props, and doesn't have state), could be fairly verbose: const Username = React.createClass({ render() { return <p>The logged in user is: {this.props.username}</p>; }, }); // OR: class Username extends React.Component { render() { return <p>The logged in user is: {this.props.username}</p>; } } React 0.14 introduced functional stateless components (or, from now on, FSCs), which lets you express the above more succinctly: const Username = function(props) { return <p>The logged in user is: {props.username}</p>; }; Which, via ES2015 arrow functions, destructuring and implicit returns can be cut down really nicely: const Username = ({ username }) => <p>The logged in user is: {username}</p>; FSCs not only provide a cleaner syntax but also have some other benefits that I'd like to talk about today, along with a couple of gotchas and things to look out for. It's also important to note that you can have stateless class components, and that in the future we might be able to have functional, stateful components. Tyler McGinnis' post on the different types of components does a great job of laying out all the different terminology. I think the primary benefit of FSCs is simplicity, and to me they act as a visual signal: "this component is solely props in, rendered UI out". If I see a class component, I do have to scan through to see what lifecycle methods it may be using, and what callbacks it may have. If I see an FSC, I know it isn't doing anything fancy. There are definitely times I'll write a stateless class component so I can define callback methods as class properties (especially if I'm passing prop values into a callback prop), but I'll write FSCs to signal that "this is a very strai