filter features

This commit is contained in:
Jonathan Branan 2025-01-10 10:27:03 -06:00
parent 8a6215098b
commit 9fb26add97
3 changed files with 692 additions and 885 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,48 +1,73 @@
import * as React from 'react';
const list = [
{
title: 'React',
url: 'https://reactjs.org/',
author: 'Jordan Walke',
num_comments: 3,
points: 4,
objectID: 0,
},
{
title: 'Redux',
url: 'https://redux.js.org/',
author: 'Dan Abramov, Andrew Clark',
num_comments: 2,
points: 5,
objectID: 1,
},
];
const App = () => {
const stories = [
{
title: 'React',
url: 'https://reactjs.org/',
author: 'Jordan Walke',
num_comments: 3,
points: 4,
objectID: 0,
},
{
title: 'Redux',
url: 'https://redux.js.org/',
author: 'Dan Abramov, Andrew Clark',
num_comments: 2,
points: 5,
objectID: 1,
},
];
function App() {
const [searchTerm, setSearchTerm] = React.useState("Redux");
const handleSearch = (event) => {
setSearchTerm(event.target.value);
};
const searchedStories = stories.filter((story) =>
story.title.toLowerCase().includes(searchTerm.toLowerCase())
);
return (
<>
<div>
<h1>
hello
</h1>
<hr />
<label htmlFor='search'>Search:</label>
<input id="search" type="search"></input>
</div>
<ul>
{list.map(function (item) {
return <li key={item.objectID}>
<span><a href={item.url}>{item.title}</a></span>
<span>{item.author}</span>
<span>{item.num_comments}</span>
<span>{item.points}</span>
</li>
})}
</ul>
</>
);
}
<h1>My Hacker Stories</h1>
export default App;
<Search onSearch={handleSearch} />
<hr />
<List list={searchedStories} />
</div>
);
};
const Search = (props) => (
<div>
<label htmlFor="search">Search: </label>
<input id="search" type="text" value={props.search} onChange={props.onSearch} />
</div>
);
const List = (props) => (
<ul>
{props.list.map((item) => (
<Item key={item.objectID} item={item} />
))}
</ul>
);
const Item = (props) => (
<li>
<span>
<a href={props.item.url}>{props.item.title}</a>
</span>
<span>{props.item.author}</span>
<span>{props.item.num_comments}</span>
<span>{props.item.points}</span>
</li>
);
export default App;

View File

@ -1,10 +1,9 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.jsx'
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
createRoot(document.getElementById('root')).render(
<StrictMode>
ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
<App />
</StrictMode>,
)
</React.StrictMode>
);