shangsunset
shangsunset

Reputation: 1615

pass function as state through Link in react router v1.0

Is possible to pass a function as state with Link?

const userAndEvalSubmissions = {
  'evalSubmissions': evalSubmissions,
  'user': this.props.user,
  'changeScore': this.changeScore // a method in component
  }

<Link
  className="btn btn-success"
  to={}
  state={userAndEvalSubmissions}>
  Scores
</Link>

I tried passing it along with other objects but only objects got through. Thanks.

Upvotes: 2

Views: 972

Answers (1)

Michelle Tilley
Michelle Tilley

Reputation: 159105

No, this goes into the location state and thus must be serializable. Per MDN's History API docs:

The state object is a JavaScript object which is associated with the new history entry created by pushState(). ... The state object can be anything that can be serialized.

Upvotes: 1

Related Questions