import React, {useState} from 'react';
import ItemsList from './ItemsList';
import AddItemForm from './AddItemForm';

const ItemsApp = () => {
    const [items, setItems] = useState([]);

    const addItems = (newitems) => {
        setItems(items.concat(newitems));
    };

    const removeItem = (index) => {
        let res = items.filter(item => items.indexOf(item) !== index);
        setItems(res);
    };

    return (
        <div>
            <ItemsList items={items} removeItem={removeItem} />
            <AddItemForm addItems={addItems} />
        </div>
    );


}

export default ItemsApp;