0

How do I pass the Link component's "ischecked" state to the input below? My goal is to click a button on some other component, which sets the input box to true.

<Link
     to={{pathname: "/Module1",
            state: {
                ischecked: false,
                },
              }}
              className={styles.menuCard}>
              <h2>Introduction &rarr;</h2>
              <p>Lesson 1</p>
              <input className={styles.checkbox} type="checkbox" 
              checked={ischecked} /> <<--cant access? how to access?
</Link>
lache
  • 608
  • 2
  • 12
  • 29

1 Answers1

0

I see, the isChecked is a state,

  const App = () => {
    const [isChecked, setChecked] = useState(false)
    const onChange = e => { setChecked(e.target.checked) }

    return <input type="checkbox" checked={isChecked} onChange={onChange} />
  }

Once you capture the state behavior, then you can send this flag to anywhere in your code.

windmaomao
  • 7,120
  • 2
  • 32
  • 36
  • Thank you, what might be slightly diffeerent is that I am clicking a button on a seperate component, in fact the one "Module1" compoent which changes the checked box to true. So i need to be able to change the value of the input checkbox from the component the Link directs to. (module1) – lache Sep 08 '21 at 13:14