top of page
Logo der Online Agentur mdwp

Function

React JS is a JavaScript library for building user interfaces. One of the fundamental terms in React JS is a function. In React, a function is a JavaScript function, which is a block of code designed to perform a particular task. A JavaScript function is executed when it is invoked (called), and it can also accept parameters and return a value.

In the context of React, functions are often used to define functional components. A functional component is essentially a JavaScript function that accepts props as an argument and returns a React element. The returned React element usually describes what should appear on the screen in terms of other React components. These React components can be either standard HTML tags or other user-defined components.

Here is an example of a simple functional component in React:

```jsx
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}

//You can call this component in later code like this
<Welcome name="Sara" />
```

In the above code, `Welcome` is a functional component that accepts a single prop, `props.name`, and returns a React element that represents an `<h1>` tag with the text "Hello, {props.name}" inside it. When we want to use this component and pass data to it, we can do it like this: `<Welcome name="Sara" />`, and it will output: `<h1>Hello, Sara</h1>`.

bottom of page