Questions tagged [react-functional-component]

Function components in React are plain JavaScript functions that are used as React components. They have access to component features via Hooks. Use this tag for questions regarding the usage or behavior of function components. Do not use this tag if the question just uses them, but doesn't specifically asks about them.

Function components (misleadingly also known as "functional" components or stateless components) are JavaScript functions that are used as components. They are essentially render functions (their return value determines what the component renders).

They receive props as an argument.

This is an example of a function component:

function HelloWorld({ color }) {
  return <div style={{ color }}>Hello World!</div>;
}

ReactDOM.render(
  <HelloWorld color="blue" />, 
  document.body
);

Function components are called stateless because they don't have a component instance bound to them, but with the addition of Hooks, they also have access to state, commit-phase side effects, etc.

Because Hooks can't be used with class components, function components have slightly different features and use-cases, and they are not always interchangeable with class components.

Official documentation: Components and Props

1301 questions
-2
votes
1 answer

How to call a Function in UseEffect?

I want to call below mentioned function onSaveInputValue into the useEffect so that, my component can have passed value in childInputValue hook whenever the page gets loaded. const onSaveInputValue = (value) => { …
-2
votes
1 answer

convert function components to class components

I have this class component here class App extends React.Component { getHowler() { this.player.howler; } getDuration() { this.player.duration(); } getSeek() { this.player.seek(); } setSeek() { this.player.seek(0.5); …
user12208384
-2
votes
2 answers

Reactjs functional component common logic extraction

I have a few functional components with a few common variables and functions. Please see below. const Customer = () => { const [isReleased, setIsReleased] = useState(false) const release = () => { setIsReleased(true) } } const…
Lakmal Premaratne
  • 1,159
  • 7
  • 18
  • 34
-2
votes
1 answer

Getting map properties using react-google-maps in functional component?

I am trying to access the current zoom or center of the map but I am getting some errors. I am new to React and I am not exactly sure what I am doing but I tried to attach a ref to the GoogleMap component const refMap = useRef(null); const…
-2
votes
1 answer

How to solve the React error: Cannot read 'Props' of undefined

I'm trying out to work on integrating a library called react-phone-number-input with my multi-step react form as per the following as a functional component: import React, { useState } from "react"; import Helmet from "react-helmet"; import…
-3
votes
1 answer

Missing Semicolon error on ReactJS Context even though there is no need for a semi-colon

I tried to use the context hook on React. After importing the context from '.App' and declared it using useContext it's showing a missing semicolon error on line 6 where there is no need for a semi-colon. The code to the error is given below. import…
Milan
  • 153
  • 1
  • 2
  • 12
-3
votes
3 answers

Getting error while using useState with textarea

I am getting this warning. Warning: A component is changing a controlled input to be uncontrolled. This is likely caused by the value changing from a defined to undefined, which should not happen. Decide between using a controlled or uncontrolled…
-3
votes
4 answers

Function inside functional component in React

I am trying to execute a function inside functional component in React. My code is like below import logo from './logo.svg'; import './App.css'; function App() { function checkvalue(checkboxElem) { if (checkboxElem.checked) { …
abu abu
  • 6,599
  • 19
  • 74
  • 131
-3
votes
3 answers

conditional rendering react component

Problem Statement React element not loading on conditional rendering What I have done till now I have a simple condition and I want to render components based on that. Here's how it looks like. I want to render IoMdAdd when true true ?…
Sarthak Batra
  • 487
  • 2
  • 10
  • 24
1 2 3
86
87