Skip to content

Instantly share code, notes, and snippets.

View DJanoskova's full-sized avatar
🐱

Dana Janoskova DJanoskova

🐱
View GitHub Profile
import React, { useState } from 'react';
const Form = () => {
const [name, setName] = useState('');
const handleChange = e => {
setName(e.target.value);
}
const handleSubmit = () => {
const CustomInput2 = ({ onChange }) => {
const handleChange = (e) => {
const newValue = getParsedValue(e.target.value);
onChange(newValue);
};
return (
<Input onChange={handleChange} />
)
}
const CustomInput1 = ({ onChange }) => {
return (
<Input onChange={e => {
const newValue = getParsedValue(e.target.value);
onChange(newValue);
}} />
)
}
const getUserRole = (roles) => {
if (roles.includes('admin')) return 'Admin';
if (roles.includes('maintainer')) return 'Maintainer';
return 'Developer';
}
const UserCard = ({ user }) => {
return (
<ul>
<li>{user.name}</li>
const UserCard = ({ user }) => {
const getUserRole = () => {
const { roles } = user;
if (roles.includes('admin')) return 'Admin';
if (roles.includes('maintainer')) return 'Maintainer';
return 'Developer';
}
return (
<ul>
const NestedComponent = () => {
// ...
if (isLoading) return <Spinner />
return (
<>
<h2>Some heading</h2>
<p>Some description</p>
</>
const NestedComponent = () => {
// ...
return (
<>
{!isLoading ? (
<>
<h2>Some heading</h2>
<p>Some description</p>
</>
export const UserContainer = () => {
const [user, setUser] = useState(null);
// do some apiCall here
return (
<div>
{user ? <UserCard user={user} /> : 'No data available'}
</div>
);
import React, { useState } from "react";
import PropTypes from "prop-types";
export const UserCard = ({ user }) => {
return (
<ul>
<li>{user.name}</li>
<li>{user.age}</li>
<li>{user.email}</li>
</ul>
import React from "react";
import PropTypes from "prop-types";
const UserCard = ({ user }) => {
return (
<ul>
<li>{user.name}</li>
<li>{user.age}</li>
<li>{user.email}</li>
</ul>