Skip to content

Does the writing of nested createMemo make sense? #350

@oligay666

Description

@oligay666

IMPORTANT: If you have a question or an idea for a new feature use Github Discussions instead

Describe the bug
In the source code, such as Provider, the implementation of nested createMemo is used, but I found that nested createMemo should have some problems. For example, the following example

To Reproduce
Provide a code snippet and steps to reproduce the behavior:

  1. run this code
import { createState, createEffect, createMemo, createMutable } from 'solid-js'
import { render } from 'solid-js/web'

function App() {
  const state  = createMutable({
      school: 'school',
      home: 'home'
  })

  const getAll = createMemo(() => {
    const home = createMemo(() => {
      console.log('Memo: ', state.home)
      return state.home
    })
    const school = createMemo(() => {
      console.log('Memo: ', state.school)
      return state.school
    })
    return home() + school()
  })


  const click = () => {
    state.school = state.school + '.'
  }
          
  
  return (
    <div onClick={click}>
      {state.home + state.school}
      <br/>
      {getAll()}
    </div>
  )
}

render(() => <App />, document.getElementById('app'))

Expected behavior
Only 'Memo: school' is triggered

The End
Does the source code need to cancel the writing of nested createMemo?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions