Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

reactjs - Need better suggestion for naming wrapping components in React

I often find that I want to have a react wrapping component around another component because of the nature of how React Hooks works with React Context. That is, if I have dependencies such that I want to use two different contexts (that are based on hooks) where one depends on the other I need to create a wrapping component as I'm showing below.

My question/problem is what to name the "inner" or "child" component. Both InnerComponent and ChildComponent don't feel like good choices. Suggestions?

const LayoutChild = ({ year, children, codeCampYears }) => {
  const [state, send, service] = useMachine(svccUiMachine, codeCampYears)
  const machine = [state, send, service];
  return (
    <SvccUiMachineContext.Provider value={machine}>
      {children}
    </SvccUiMachineContext.Provider>
  );
};

const Layout = ({ year, children }) => {
  const { data, loading } = useAuthInfo();
  return (
      <LayoutChild year={year} codeCampYears={codeCampYears}>
        {children}
      </LayoutChild>
  );
};

export default Layout;

The above code is not exactly right, but the idea is that I'm exporting for consumption just the Layout component, and it uses LayoutChild and I'm not liking that name.

question from:https://stackoverflow.com/questions/65904606/need-better-suggestion-for-naming-wrapping-components-in-react

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

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...