diff --git a/src/components/ProjectName.tsx b/src/components/ProjectName.tsx index 6a52be8d..b14ded79 100644 --- a/src/components/ProjectName.tsx +++ b/src/components/ProjectName.tsx @@ -1,6 +1,6 @@ import "./TextInput.scss"; -import React, { Component } from "react"; +import React, { useState } from "react"; import { focusNearestParent } from "../utils"; import "./ProjectName.scss"; @@ -12,22 +12,18 @@ type Props = { isNameEditable: boolean; }; -type State = { - fileName: string; -}; -export class ProjectName extends Component { - state = { - fileName: this.props.value, - }; - private handleBlur = (event: any) => { +export const ProjectName = (props: Props) => { + const [fileName, setFileName] = useState(props.value); + + const handleBlur = (event: any) => { focusNearestParent(event.target); const value = event.target.value; - if (value !== this.props.value) { - this.props.onChange(value); + if (value !== props.value) { + props.onChange(value); } }; - private handleKeyDown = (event: React.KeyboardEvent) => { + const handleKeyDown = (event: React.KeyboardEvent) => { if (event.key === "Enter") { event.preventDefault(); if (event.nativeEvent.isComposing || event.keyCode === 229) { @@ -37,29 +33,25 @@ export class ProjectName extends Component { } }; - public render() { - return ( -
- - {this.props.isNameEditable ? ( - - this.setState({ fileName: event.target.value }) - } - /> - ) : ( - - {this.props.value} - - )} -
- ); - } -} + return ( +
+ + {props.isNameEditable ? ( + setFileName(event.target.value)} + /> + ) : ( + + {props.value} + + )} +
+ ); +};