Skip to content

React, queries, and field-level reactivity? #1010

Answered by beorn
beorn asked this question in Q&A
Discussion options

You must be logged in to vote

Okay, answering my own question — by splitting into a 'list' query and a 'details' query, and by using React.memo on the Item (that only gets id as prop), minimal number of re-renders are performed. But of course, this means extra memory use (memo) and extra queries (list/detail split).

If you see a better way, please let me know.

import React, { useState } from "react"
import Todos from "../../models/Todos"
import useReactivity from "../../utils/useReactivity"

export default function App() {
  return (
    <>
      <Input />
      <List />
    </>
  )
}

function List() {
  console.warn("--- rendering List")
  const items = useReactivity(
    () => Todos.find({}, { fields: { id: 1 } }).f…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@beorn
Comment options

Answer selected by beorn
@maxnowack
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants