JAVASCRIPT
function component example in react
import React from 'react';
const Component = () => {
return (
<h1>Component</h1>
)
}
export default Component;
function component in react
// function component in react
import React from 'react';
const FunctionComponent = function() {
return (
<div>
<h1>React Function Component</h1>
</div>
)
}
export default FunctionComponent;
react functional components
const component = () => {
console.log("This is a functional Component");
}
function component react js
function app() {
return (
<div>
<h1>Hello World</h1>;
</div>
);
}
functional component react
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}
function App() {
return (
<div>
<Welcome name="Sara" /> <Welcome name="Cahal" /> <Welcome name="Edite" /> </div>
);
}
ReactDOM.render(
<App />,
document.getElementById('root')
);
create functional component react
import React from 'react'; const App = () => { const greeting = 'Hello Function Component!'; return <Headline value={greeting} />;}; const Headline = ({ value }) => <h1>{value}</h1>; export default App;
React function component
import React from 'react';
const component = () => {
return (
<div>
<h1>Title</h1>
<p>Description</p>
</div>
)
}
export default Component;
functional components react
function Comment(props) {
return (
<div className="Comment">
<div className="UserInfo">
<img className="Avatar"
src={props.author.avatarUrl}
alt={props.author.name}
/>
<div className="UserInfo-name">
{props.author.name}
</div>
</div>
<div className="Comment-text">
{props.text}
</div>
<div className="Comment-date">
{formatDate(props.date)}
</div>
</div>
);
}
react functional component example
function Greeting(props) {
return <h1> Hello, {props.name}! </h1>
}
React functional component
export const Comp = (x : props) => {}
functional component
const MySubComponent = (props) => {
if (props.display) {
return <p>This text is displayed</p>
}
}
class MyComponent extends React.Component {
render() {
return (
<MySubComponent display={true} />
)
}
}
functional component
const MySubComponent = (props) => {
if (props.display) {
return <p>This text is displayed</p>
}
}
class MyComponent extends React.Component {
render() {
return (
<MySubComponent display={true} />
)
}
}