What is a state in <Link> component of React Router?

后端 未结 4 2109
遥遥无期
遥遥无期 2021-01-04 12:11

Here is a screenshot from their docs about component

  1. What state do they mean? A Redux state?
4条回答
  •  梦谈多话
    2021-01-04 12:29

    state is a property that's part of the object you can provide to the to prop of the component.

    It is particularly useful if you want to send data from the current view to one the directs you to, without using common techniques such as setting URL parameters or using libraries, such as Redux.

    There isn't much official information about the state key, but here's what I found in the source code of that component:

    Links may pass along location state and/or query string parameters in the state/query props, respectively.

    So basically, it's like sending props to a component from a parent. Here, you are sending "state" from the current view to the target view. That's about it, really.

提交回复
热议问题