import React, { useEffect } from 'react'; import { areEqual } from 'react-window'; import tw from 'twin.macro'; interface EditableHeaderProps { value: string; isEditable: boolean; onChange?: (value: any) => void; children: any; } export const EditableHeader = React.memo(function (props: EditableHeaderProps) { const { value, isEditable, onChange, children, } = props; const [isEditing, setIsEditing] = React.useState(false); const [editedValue, setEditedValue] = React.useState(value); useEffect(() => { setEditedValue(value); }, [value]); const onSubmit = () => { onChange?.(editedValue); setIsEditing(false); } if (!isEditable) return children return isEditing ? (
) : ( ); }, areEqual);