Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to create a button for the Taste : `Good`, and the Comments: `3/4`, Price: `Low`; which are the defaut value (from the match.json) but the user can have the possibility to modify these default values. So when you click you have a dropbox with different options. For instance let's take `Taste` by default it's `Good` (display in green) but I want to get the possibility to choose `Bad` the color for this button will be red and `Medium`, orange color. Same idea for Comment.
For Price, it will be only checkbox that is already in blue and the user have the possibilty to unckeck it.

Here the link for the code: <a href="https://codesandbox.io/s/react-how-do-i-display-specific-data-from-json-that-fullfill-a-condition-forked-z37eu1?file=/src/Button.jsx"> code_link</a> (go to /menu/Menu1/ click on Pea Soup for example.


What I have tried:

<pre>
     export default function MenuDisplay() {
            const { menuId, itemId } = useParams();
            const { match } = JsonData;
        
            const matchData = match.find((el) => el._id_menu === 
               menuId)?._ids ?? [];
            const item = matchData.find((el) => el._id === itemId);
        
            return (
                <>
                    <h1>Menu Item</h1>
                    <div>
                        <div className="TextStyle"> Name : <button> 
                              {item.name} </button>  </div>
                        <div className="TextStyle">Description: 
                              {item.description} </div> 
                        <div className="TextStyle">Description: 
                              {item.price} </div>
                        <div className="TextStyle"> Price : {item.taste} 
                        </div>
                        <div className="TextStyle"> Comments : 
                             {item.comment} </div>
                    </div>
                </>
            );
        }


Here a picture to get the idea:
<a href="https://imgur.com/a/YYeDd7O">image_link</a>
Posted
Updated 16-Apr-22 2:42am
v2

1 solution

I am not a React programmer, however a quiick Google Search has many how-to tutorials: react custom select dropdown[^]

Find one that best suits your needs.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900