reactjs - React set focus to grandchild in parent child grandchild hierarchy -


i have classic parent->child->grandchild hierarchy of react components. when click on link in parent want set focus textbox in grandchild component.

my first attempt pass callback function through props of parent , child , grandchild. grandchild called callback, passing ref property callback. reference stored parent component when link clicked in parent use getdomnode of referenced grandchild component , call focus() set focus. configuration worked.

but wan't happy having pass callback via prop in child component. child component had no need prop , passing on grandchild. afaik classic react problem. if sometime later added level hierarchy between child , grandchild, i'd have remember make pass prop down (and change tests!).

i thought, flux pattern me here? wasn't 1 of advantages of flux decouple dependencies between these hierarchical structures? i'm using reflux part of application why don't use that. child component mounts place ref value reflux store , when parent link clicked grabs value store , calls .focus on it.

then realized i'm rendering list. 1 item in list consists of parent->child->grandchild , next item in list consists of parent->child->grandchild, etc... problem flux stores singletons. each grandchild rendered pass it's ref value store , overwrite previous one. thought ok, i'll use array of items in store, way can store ref of each grandchild , when link clicked in parent can corresponding grandchild in array , set focus it.

my question is, (finally we're getting there :)

  1. is reasonably approach?
  2. should using flux stores kind of behavior? i.e. storing ref values in flux store?


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -