0

I have a variable [key, setKey] with state set to some string which I would like passed down to some other component. A problem I'm having is that the child component does not recognise it.

function AppWindow() {


  const [key, setKey] = useState('test');


return (
 
      <Box sx={{}}>

            <Settings2 key={key} setKey={setKey}/>

      </Box>


function Settings2({key, setKey}) {

const handleChange = (e) => {
        

        
        setKey('e');
        console.log(key);
       

      };

return(
<form>
                                    <Input
                                            variant= 'standard'
                                            type='text'
                                            disablePortal
                                            id="combo-box-demo"
                                            sx={{ width: '100%', input: {color: '#d4e1ed'} }}
                                            placeholder='Enter Your Key'
                                            onChange={(e) => handleChange(e)}
                                    />
                                 </form>
...



Even when I explicitly try to set a string it's still undefined for some reason. Did I pass it down correctly?

1 Answer 1

4

key is a reserved prop for React to identify a given component. Given that you can't extract it as a prop. you should rename your prop a different name.

Sign up to request clarification or add additional context in comments.

Comments

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.