Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
353 views
in Technique[技术] by (71.8m points)

reactjs - Can't render react component with props from mobx

I'm trying to render component inside another component in React. I can't understand why optionwrapper doesn't renders when fetching is done. It would be perfect if someone can explain why it doen't work

const SearchResults = () => {
  useEffect( () => {
    GlobalStore.setOptions();
  }, []);
return(
    
      <div className={styles.column}>
        {
          GlobalStore.getOptions.result=='OK' &&
          
          <OptionWrapper options={ GlobalStore.options.data.body} />
        }
       
   </div>
)}
question from:https://stackoverflow.com/questions/65900586/cant-render-react-component-with-props-from-mobx

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think you should wrap SearchResults component using observer

const SearchResults =observer(() => {
  useEffect( () => {
    GlobalStore.setOptions();
  }, []);
return(
    
      <div className={styles.column}>
        {
          GlobalStore.getOptions.result=='OK' &&
          
          <OptionWrapper options={ GlobalStore.options.data.body} />
        }
       
   </div>
)})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...