Chap06 -> Understanding controlled components
parent
c913b32ddb
commit
228c9e9417
|
@ -1,14 +1,23 @@
|
|||
/** @jsxImportSource @emotion/react */
|
||||
import { css } from '@emotion/react';
|
||||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { Link, useSearchParams } from 'react-router-dom';
|
||||
|
||||
import { UserIcon } from './Icons';
|
||||
import { fontFamily, fontSize, gray1, gray2, gray5 } from './Styles';
|
||||
|
||||
export const Header = () => {
|
||||
const [searchParams] = useSearchParams();
|
||||
const criteria = searchParams.get('criteria') || '';
|
||||
const [search, setSearch] = React.useState(criteria);
|
||||
|
||||
const handleSearchInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
console.log(e.currentTarget.value);
|
||||
setSearch(e.currentTarget.value);
|
||||
};
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
console.log(search);
|
||||
};
|
||||
|
||||
return (
|
||||
|
@ -38,26 +47,29 @@ export const Header = () => {
|
|||
>
|
||||
Q & A
|
||||
</Link>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search ..."
|
||||
onChange={handleSearchInputChange}
|
||||
css={css`
|
||||
box-sizing: border-box;
|
||||
font-family: ${fontFamily};
|
||||
font-size: ${fontSize};
|
||||
padding: 8px 10px;
|
||||
border: 1px solid ${gray5};
|
||||
border-radius: 3px;
|
||||
color: ${gray2};
|
||||
background-color: white;
|
||||
width: 200px;
|
||||
height: 30px;
|
||||
:focus {
|
||||
outline-color: ${gray5};
|
||||
}
|
||||
`}
|
||||
/>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search ..."
|
||||
value={search}
|
||||
onChange={handleSearchInputChange}
|
||||
css={css`
|
||||
box-sizing: border-box;
|
||||
font-family: ${fontFamily};
|
||||
font-size: ${fontSize};
|
||||
padding: 8px 10px;
|
||||
border: 1px solid ${gray5};
|
||||
border-radius: 3px;
|
||||
color: ${gray2};
|
||||
background-color: white;
|
||||
width: 200px;
|
||||
height: 30px;
|
||||
:focus {
|
||||
outline-color: ${gray5};
|
||||
}
|
||||
`}
|
||||
/>
|
||||
</form>
|
||||
<Link
|
||||
to="signin"
|
||||
css={css`
|
||||
|
|
Loading…
Reference in New Issue