简体   繁体   中英

How to set initial variables in relay modern?

started relay at learnrelay.org, from the tutorial the code to set initial variables https://www.learnrelay.org/queries/variables/ is like this:

export default Relay.createContainer(
  ListPage,
  {
    initialVariables: {
      sortOrder: 'id_DESC'
    },
    fragments: {
      viewer: () => Relay.QL`
        fragment on Viewer {
          allPokemons (first: 1000, orderBy: $sortOrder) {

we usually assign variables in relay classic like this, but this code throws an error in relay modern and I don't know why?

export default createPaginationContainer(TodoList,
  initialVariables: {
    first: 10,
  }, 
  fragments: {
  viewer: graphql`
    fragment TodoList_viewer on User {
      todos( # we need to expose todos on user so we can check if todo text already exist and sync in database 
        first: $first 
      ) @connection(key: "TodoList_todos") { #assign a key of connection that can be used shared updater

You can't use initialVariables in Relay Modern - see this link in the docs . Note that as of now, the documentation for migrating away from these functions is extremely brief.

If you're working on this right now, there's a pending update to the RefetchContainer documentation that shows how to properly fetch and refetch your view based on variables.

If you're only using the variables for pagination, check out PaginationContainer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM