0

The code for use state and handling inputs is given below. I can't get my game name in console on selecting, why?

const [tour, setTour] = useState({
        cafename: "", contactno: "", state: "", address: "", game: "", date: "", prizepool: ""
    });

    var name, value;
    const handleInputs = (e) => {
        console.log(e);

        name = e.target.name;
        value = e.target.value;

        setTour({ ...user, [name]: value });
    }

The select code is given below.

<div className="form-group">
                                <label for="games">Games</label>
                                <select class="custom-select" name= "game" value={tour.game} onChange={handleInputs}>
                                    <option selected>Select game</option>
                                    <option value="leagueoflegends">LEAGUE OF LEGENDS</option>
                                    <option value="valorant">VALORANT</option>
                                    <option value="rainbow6">RAINBOW 6 SIEGE</option>
                                    <option value="dota2">DOTA 2</option>
                                    <option value="cs">CS GO </option>

                                    placeholder="Enter games"
                                </select>
                            </div>

1 Answer 1

1

CheckBox has checked property for value:

const handleInputs = (e) => {
    name = e.target.name;
    value = e.target.type === 'checkbox' ? e.target.checked : e.target.value;

    setTour(state => { ...state, [name]: value });
}
Sign up to request clarification or add additional context in comments.

4 Comments

Is my checkbox code right?
What checkbox? You just have a select in html code.
Sorry, Is my select code right?
Yes. Your select code is correct. But change the setTour: setTour(state => { ...state, [name]: value });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.