How to identify component name from a object array










0















Currently I have the following



methodName = () => 
const
collectionOfComponents
...
...
= this.props;

return (
<Wrapper1>
collectionOfComponents.map((oneComponent, index) => (
<Wrapper2
..props
>
oneComponent.component
</Wrapper2>
)
</Wrapper1>
);
;


And for collectionOfComponents I am passing in the following



collectionOfComponents=[
<ComponentOne prop1... prop2... />,
<ComponentOne prop1... prop2... />,
<ComponentTwo prop1... prop2... />
]


Is there a way to identify when ComponentTwo has been passed through so that I can perform a different render. I'm not sure how to do this



EDIT
Sorry, should of made this clear, but i'm not looking to change the render method in the map i'm looking for a separate function to first check to see if componentTwo exists in the array at any time and then (maybe) use a tertiary to call one of two methods which will be two different return methods. I will then call the function in the render method










share|improve this question




























    0















    Currently I have the following



    methodName = () => 
    const
    collectionOfComponents
    ...
    ...
    = this.props;

    return (
    <Wrapper1>
    collectionOfComponents.map((oneComponent, index) => (
    <Wrapper2
    ..props
    >
    oneComponent.component
    </Wrapper2>
    )
    </Wrapper1>
    );
    ;


    And for collectionOfComponents I am passing in the following



    collectionOfComponents=[
    <ComponentOne prop1... prop2... />,
    <ComponentOne prop1... prop2... />,
    <ComponentTwo prop1... prop2... />
    ]


    Is there a way to identify when ComponentTwo has been passed through so that I can perform a different render. I'm not sure how to do this



    EDIT
    Sorry, should of made this clear, but i'm not looking to change the render method in the map i'm looking for a separate function to first check to see if componentTwo exists in the array at any time and then (maybe) use a tertiary to call one of two methods which will be two different return methods. I will then call the function in the render method










    share|improve this question


























      0












      0








      0








      Currently I have the following



      methodName = () => 
      const
      collectionOfComponents
      ...
      ...
      = this.props;

      return (
      <Wrapper1>
      collectionOfComponents.map((oneComponent, index) => (
      <Wrapper2
      ..props
      >
      oneComponent.component
      </Wrapper2>
      )
      </Wrapper1>
      );
      ;


      And for collectionOfComponents I am passing in the following



      collectionOfComponents=[
      <ComponentOne prop1... prop2... />,
      <ComponentOne prop1... prop2... />,
      <ComponentTwo prop1... prop2... />
      ]


      Is there a way to identify when ComponentTwo has been passed through so that I can perform a different render. I'm not sure how to do this



      EDIT
      Sorry, should of made this clear, but i'm not looking to change the render method in the map i'm looking for a separate function to first check to see if componentTwo exists in the array at any time and then (maybe) use a tertiary to call one of two methods which will be two different return methods. I will then call the function in the render method










      share|improve this question
















      Currently I have the following



      methodName = () => 
      const
      collectionOfComponents
      ...
      ...
      = this.props;

      return (
      <Wrapper1>
      collectionOfComponents.map((oneComponent, index) => (
      <Wrapper2
      ..props
      >
      oneComponent.component
      </Wrapper2>
      )
      </Wrapper1>
      );
      ;


      And for collectionOfComponents I am passing in the following



      collectionOfComponents=[
      <ComponentOne prop1... prop2... />,
      <ComponentOne prop1... prop2... />,
      <ComponentTwo prop1... prop2... />
      ]


      Is there a way to identify when ComponentTwo has been passed through so that I can perform a different render. I'm not sure how to do this



      EDIT
      Sorry, should of made this clear, but i'm not looking to change the render method in the map i'm looking for a separate function to first check to see if componentTwo exists in the array at any time and then (maybe) use a tertiary to call one of two methods which will be two different return methods. I will then call the function in the render method







      reactjs ecmascript-6 react-props






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 '18 at 21:54







      zeduke

















      asked Nov 12 '18 at 21:07









      zedukezeduke

      8518




      8518






















          4 Answers
          4






          active

          oldest

          votes


















          1














          When you use a component, React creates an Element. Each element has a type property. The type is the class of function for component elements, or a string for DOM elements ('button').



          To find the component that created the element, compare the type of the element to the Function of Class that created it:






          const ComponentOne = () => 1;
          const ComponentTwo = () => 2;
          class ComponentThree extends React.Component
          render()
          return 3;



          const Wrapper = ( children ) => (
          <div>
          React.Children.map(children, (El) =>
          switch(El.type)
          case ComponentOne:
          return <div className="red">El</div>;
          case ComponentTwo:
          return <div className="blue">El</div>;
          case ComponentThree:
          return <div className="green">El</div>;


          return null;
          )
          </div>
          );

          ReactDOM.render(
          <Wrapper>
          <ComponentOne />
          <ComponentOne />
          <ComponentTwo />
          <ComponentThree />
          </Wrapper>,
          demo
          );

          .red background: red; 
          .blue background: blue;
          .green background: green;

          <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
          <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
          <div id="demo"></div>








          share|improve this answer























          • or in the case of needing to compare against strings (for whatever reason) El.type.name.

            – rlemon
            Nov 12 '18 at 21:42











          • You should note that functions' and classes' names might change after minification.

            – Ori Drori
            Nov 12 '18 at 21:46











          • Is there a way to check if componentTwo exists in a separate function and then decide what to do? e.g. call one function if componentTwo exists, if not call another?

            – zeduke
            Nov 12 '18 at 21:57











          • Do whatever you want in the switch. I've returned the element, you call a function that will return something else.

            – Ori Drori
            Nov 12 '18 at 21:58


















          0














          const isComponentTwo = collectionOfComponents.some(component => component.type.displayName.includes('ComponentTwo'));


          The above will return true if at least one component in the collectionOfComponents is ComponentTwo.



          This is not advisable however. Using displayName or type for production should never be used. This is because during, for example, minification the displayName and type will change, so the logic you are expecting will not occur in the way you are expecting.



          The following states:




          The displayName string is used in debugging messages. Usually, you don’t need to set it explicitly because it’s inferred from the name of the function or class that defines the component. You might want to set it explicitly if you want to display a different name for debugging purposes or when you create a higher-order component




          A better solution would be to add some sort of flagProp to your component.
          For example



          decideWhatToDo = () => 
          const flagPropName = this.props;
          return flagPropName
          ? this.methodOne()
          : this.methodTwo();



          In the two methods you can then decide what you want to do if componentTwo exists or if it doesn't exist






          share|improve this answer
































            -1














            Check in the array using indexOf:



            collectionOfComponents.indexOf('ComponentTwo') !== -1 // found





            share|improve this answer

























            • Components will not be unique there could be 5 ComponentOne and two ComponentTwo or there could be 7ComponentTwo and 1 ComponentOne

              – zeduke
              Nov 12 '18 at 21:22











            • Anyways, you are just wondering if that component is found, right?

              – Bhojendra Rauniyar
              Nov 12 '18 at 21:24











            • correct if a certain component exists in the array

              – zeduke
              Nov 12 '18 at 21:25











            • Let me know if you have any query.

              – Bhojendra Rauniyar
              Nov 12 '18 at 21:25


















            -1














            Maybe you can use this way or simulary ??



             <Wrapper1>
            {collectionOfComponents.map((oneComponent, index) => (
            <Wrapper2
            ..props
            >
            oneComponent.component instanceof ComponentTwo ? renderWasYouWant : otherRender
            </Wrapper2>
            )
            </Wrapper1>





            share|improve this answer
























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270111%2fhow-to-identify-component-name-from-a-object-array%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              When you use a component, React creates an Element. Each element has a type property. The type is the class of function for component elements, or a string for DOM elements ('button').



              To find the component that created the element, compare the type of the element to the Function of Class that created it:






              const ComponentOne = () => 1;
              const ComponentTwo = () => 2;
              class ComponentThree extends React.Component
              render()
              return 3;



              const Wrapper = ( children ) => (
              <div>
              React.Children.map(children, (El) =>
              switch(El.type)
              case ComponentOne:
              return <div className="red">El</div>;
              case ComponentTwo:
              return <div className="blue">El</div>;
              case ComponentThree:
              return <div className="green">El</div>;


              return null;
              )
              </div>
              );

              ReactDOM.render(
              <Wrapper>
              <ComponentOne />
              <ComponentOne />
              <ComponentTwo />
              <ComponentThree />
              </Wrapper>,
              demo
              );

              .red background: red; 
              .blue background: blue;
              .green background: green;

              <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
              <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
              <div id="demo"></div>








              share|improve this answer























              • or in the case of needing to compare against strings (for whatever reason) El.type.name.

                – rlemon
                Nov 12 '18 at 21:42











              • You should note that functions' and classes' names might change after minification.

                – Ori Drori
                Nov 12 '18 at 21:46











              • Is there a way to check if componentTwo exists in a separate function and then decide what to do? e.g. call one function if componentTwo exists, if not call another?

                – zeduke
                Nov 12 '18 at 21:57











              • Do whatever you want in the switch. I've returned the element, you call a function that will return something else.

                – Ori Drori
                Nov 12 '18 at 21:58















              1














              When you use a component, React creates an Element. Each element has a type property. The type is the class of function for component elements, or a string for DOM elements ('button').



              To find the component that created the element, compare the type of the element to the Function of Class that created it:






              const ComponentOne = () => 1;
              const ComponentTwo = () => 2;
              class ComponentThree extends React.Component
              render()
              return 3;



              const Wrapper = ( children ) => (
              <div>
              React.Children.map(children, (El) =>
              switch(El.type)
              case ComponentOne:
              return <div className="red">El</div>;
              case ComponentTwo:
              return <div className="blue">El</div>;
              case ComponentThree:
              return <div className="green">El</div>;


              return null;
              )
              </div>
              );

              ReactDOM.render(
              <Wrapper>
              <ComponentOne />
              <ComponentOne />
              <ComponentTwo />
              <ComponentThree />
              </Wrapper>,
              demo
              );

              .red background: red; 
              .blue background: blue;
              .green background: green;

              <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
              <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
              <div id="demo"></div>








              share|improve this answer























              • or in the case of needing to compare against strings (for whatever reason) El.type.name.

                – rlemon
                Nov 12 '18 at 21:42











              • You should note that functions' and classes' names might change after minification.

                – Ori Drori
                Nov 12 '18 at 21:46











              • Is there a way to check if componentTwo exists in a separate function and then decide what to do? e.g. call one function if componentTwo exists, if not call another?

                – zeduke
                Nov 12 '18 at 21:57











              • Do whatever you want in the switch. I've returned the element, you call a function that will return something else.

                – Ori Drori
                Nov 12 '18 at 21:58













              1












              1








              1







              When you use a component, React creates an Element. Each element has a type property. The type is the class of function for component elements, or a string for DOM elements ('button').



              To find the component that created the element, compare the type of the element to the Function of Class that created it:






              const ComponentOne = () => 1;
              const ComponentTwo = () => 2;
              class ComponentThree extends React.Component
              render()
              return 3;



              const Wrapper = ( children ) => (
              <div>
              React.Children.map(children, (El) =>
              switch(El.type)
              case ComponentOne:
              return <div className="red">El</div>;
              case ComponentTwo:
              return <div className="blue">El</div>;
              case ComponentThree:
              return <div className="green">El</div>;


              return null;
              )
              </div>
              );

              ReactDOM.render(
              <Wrapper>
              <ComponentOne />
              <ComponentOne />
              <ComponentTwo />
              <ComponentThree />
              </Wrapper>,
              demo
              );

              .red background: red; 
              .blue background: blue;
              .green background: green;

              <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
              <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
              <div id="demo"></div>








              share|improve this answer













              When you use a component, React creates an Element. Each element has a type property. The type is the class of function for component elements, or a string for DOM elements ('button').



              To find the component that created the element, compare the type of the element to the Function of Class that created it:






              const ComponentOne = () => 1;
              const ComponentTwo = () => 2;
              class ComponentThree extends React.Component
              render()
              return 3;



              const Wrapper = ( children ) => (
              <div>
              React.Children.map(children, (El) =>
              switch(El.type)
              case ComponentOne:
              return <div className="red">El</div>;
              case ComponentTwo:
              return <div className="blue">El</div>;
              case ComponentThree:
              return <div className="green">El</div>;


              return null;
              )
              </div>
              );

              ReactDOM.render(
              <Wrapper>
              <ComponentOne />
              <ComponentOne />
              <ComponentTwo />
              <ComponentThree />
              </Wrapper>,
              demo
              );

              .red background: red; 
              .blue background: blue;
              .green background: green;

              <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
              <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
              <div id="demo"></div>








              const ComponentOne = () => 1;
              const ComponentTwo = () => 2;
              class ComponentThree extends React.Component
              render()
              return 3;



              const Wrapper = ( children ) => (
              <div>
              React.Children.map(children, (El) =>
              switch(El.type)
              case ComponentOne:
              return <div className="red">El</div>;
              case ComponentTwo:
              return <div className="blue">El</div>;
              case ComponentThree:
              return <div className="green">El</div>;


              return null;
              )
              </div>
              );

              ReactDOM.render(
              <Wrapper>
              <ComponentOne />
              <ComponentOne />
              <ComponentTwo />
              <ComponentThree />
              </Wrapper>,
              demo
              );

              .red background: red; 
              .blue background: blue;
              .green background: green;

              <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
              <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
              <div id="demo"></div>





              const ComponentOne = () => 1;
              const ComponentTwo = () => 2;
              class ComponentThree extends React.Component
              render()
              return 3;



              const Wrapper = ( children ) => (
              <div>
              React.Children.map(children, (El) =>
              switch(El.type)
              case ComponentOne:
              return <div className="red">El</div>;
              case ComponentTwo:
              return <div className="blue">El</div>;
              case ComponentThree:
              return <div className="green">El</div>;


              return null;
              )
              </div>
              );

              ReactDOM.render(
              <Wrapper>
              <ComponentOne />
              <ComponentOne />
              <ComponentTwo />
              <ComponentThree />
              </Wrapper>,
              demo
              );

              .red background: red; 
              .blue background: blue;
              .green background: green;

              <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
              <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
              <div id="demo"></div>






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 12 '18 at 21:40









              Ori DroriOri Drori

              76k138092




              76k138092












              • or in the case of needing to compare against strings (for whatever reason) El.type.name.

                – rlemon
                Nov 12 '18 at 21:42











              • You should note that functions' and classes' names might change after minification.

                – Ori Drori
                Nov 12 '18 at 21:46











              • Is there a way to check if componentTwo exists in a separate function and then decide what to do? e.g. call one function if componentTwo exists, if not call another?

                – zeduke
                Nov 12 '18 at 21:57











              • Do whatever you want in the switch. I've returned the element, you call a function that will return something else.

                – Ori Drori
                Nov 12 '18 at 21:58

















              • or in the case of needing to compare against strings (for whatever reason) El.type.name.

                – rlemon
                Nov 12 '18 at 21:42











              • You should note that functions' and classes' names might change after minification.

                – Ori Drori
                Nov 12 '18 at 21:46











              • Is there a way to check if componentTwo exists in a separate function and then decide what to do? e.g. call one function if componentTwo exists, if not call another?

                – zeduke
                Nov 12 '18 at 21:57











              • Do whatever you want in the switch. I've returned the element, you call a function that will return something else.

                – Ori Drori
                Nov 12 '18 at 21:58
















              or in the case of needing to compare against strings (for whatever reason) El.type.name.

              – rlemon
              Nov 12 '18 at 21:42





              or in the case of needing to compare against strings (for whatever reason) El.type.name.

              – rlemon
              Nov 12 '18 at 21:42













              You should note that functions' and classes' names might change after minification.

              – Ori Drori
              Nov 12 '18 at 21:46





              You should note that functions' and classes' names might change after minification.

              – Ori Drori
              Nov 12 '18 at 21:46













              Is there a way to check if componentTwo exists in a separate function and then decide what to do? e.g. call one function if componentTwo exists, if not call another?

              – zeduke
              Nov 12 '18 at 21:57





              Is there a way to check if componentTwo exists in a separate function and then decide what to do? e.g. call one function if componentTwo exists, if not call another?

              – zeduke
              Nov 12 '18 at 21:57













              Do whatever you want in the switch. I've returned the element, you call a function that will return something else.

              – Ori Drori
              Nov 12 '18 at 21:58





              Do whatever you want in the switch. I've returned the element, you call a function that will return something else.

              – Ori Drori
              Nov 12 '18 at 21:58













              0














              const isComponentTwo = collectionOfComponents.some(component => component.type.displayName.includes('ComponentTwo'));


              The above will return true if at least one component in the collectionOfComponents is ComponentTwo.



              This is not advisable however. Using displayName or type for production should never be used. This is because during, for example, minification the displayName and type will change, so the logic you are expecting will not occur in the way you are expecting.



              The following states:




              The displayName string is used in debugging messages. Usually, you don’t need to set it explicitly because it’s inferred from the name of the function or class that defines the component. You might want to set it explicitly if you want to display a different name for debugging purposes or when you create a higher-order component




              A better solution would be to add some sort of flagProp to your component.
              For example



              decideWhatToDo = () => 
              const flagPropName = this.props;
              return flagPropName
              ? this.methodOne()
              : this.methodTwo();



              In the two methods you can then decide what you want to do if componentTwo exists or if it doesn't exist






              share|improve this answer





























                0














                const isComponentTwo = collectionOfComponents.some(component => component.type.displayName.includes('ComponentTwo'));


                The above will return true if at least one component in the collectionOfComponents is ComponentTwo.



                This is not advisable however. Using displayName or type for production should never be used. This is because during, for example, minification the displayName and type will change, so the logic you are expecting will not occur in the way you are expecting.



                The following states:




                The displayName string is used in debugging messages. Usually, you don’t need to set it explicitly because it’s inferred from the name of the function or class that defines the component. You might want to set it explicitly if you want to display a different name for debugging purposes or when you create a higher-order component




                A better solution would be to add some sort of flagProp to your component.
                For example



                decideWhatToDo = () => 
                const flagPropName = this.props;
                return flagPropName
                ? this.methodOne()
                : this.methodTwo();



                In the two methods you can then decide what you want to do if componentTwo exists or if it doesn't exist






                share|improve this answer



























                  0












                  0








                  0







                  const isComponentTwo = collectionOfComponents.some(component => component.type.displayName.includes('ComponentTwo'));


                  The above will return true if at least one component in the collectionOfComponents is ComponentTwo.



                  This is not advisable however. Using displayName or type for production should never be used. This is because during, for example, minification the displayName and type will change, so the logic you are expecting will not occur in the way you are expecting.



                  The following states:




                  The displayName string is used in debugging messages. Usually, you don’t need to set it explicitly because it’s inferred from the name of the function or class that defines the component. You might want to set it explicitly if you want to display a different name for debugging purposes or when you create a higher-order component




                  A better solution would be to add some sort of flagProp to your component.
                  For example



                  decideWhatToDo = () => 
                  const flagPropName = this.props;
                  return flagPropName
                  ? this.methodOne()
                  : this.methodTwo();



                  In the two methods you can then decide what you want to do if componentTwo exists or if it doesn't exist






                  share|improve this answer















                  const isComponentTwo = collectionOfComponents.some(component => component.type.displayName.includes('ComponentTwo'));


                  The above will return true if at least one component in the collectionOfComponents is ComponentTwo.



                  This is not advisable however. Using displayName or type for production should never be used. This is because during, for example, minification the displayName and type will change, so the logic you are expecting will not occur in the way you are expecting.



                  The following states:




                  The displayName string is used in debugging messages. Usually, you don’t need to set it explicitly because it’s inferred from the name of the function or class that defines the component. You might want to set it explicitly if you want to display a different name for debugging purposes or when you create a higher-order component




                  A better solution would be to add some sort of flagProp to your component.
                  For example



                  decideWhatToDo = () => 
                  const flagPropName = this.props;
                  return flagPropName
                  ? this.methodOne()
                  : this.methodTwo();



                  In the two methods you can then decide what you want to do if componentTwo exists or if it doesn't exist







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 25 '18 at 14:27

























                  answered Nov 13 '18 at 20:46









                  zedukezeduke

                  8518




                  8518





















                      -1














                      Check in the array using indexOf:



                      collectionOfComponents.indexOf('ComponentTwo') !== -1 // found





                      share|improve this answer

























                      • Components will not be unique there could be 5 ComponentOne and two ComponentTwo or there could be 7ComponentTwo and 1 ComponentOne

                        – zeduke
                        Nov 12 '18 at 21:22











                      • Anyways, you are just wondering if that component is found, right?

                        – Bhojendra Rauniyar
                        Nov 12 '18 at 21:24











                      • correct if a certain component exists in the array

                        – zeduke
                        Nov 12 '18 at 21:25











                      • Let me know if you have any query.

                        – Bhojendra Rauniyar
                        Nov 12 '18 at 21:25















                      -1














                      Check in the array using indexOf:



                      collectionOfComponents.indexOf('ComponentTwo') !== -1 // found





                      share|improve this answer

























                      • Components will not be unique there could be 5 ComponentOne and two ComponentTwo or there could be 7ComponentTwo and 1 ComponentOne

                        – zeduke
                        Nov 12 '18 at 21:22











                      • Anyways, you are just wondering if that component is found, right?

                        – Bhojendra Rauniyar
                        Nov 12 '18 at 21:24











                      • correct if a certain component exists in the array

                        – zeduke
                        Nov 12 '18 at 21:25











                      • Let me know if you have any query.

                        – Bhojendra Rauniyar
                        Nov 12 '18 at 21:25













                      -1












                      -1








                      -1







                      Check in the array using indexOf:



                      collectionOfComponents.indexOf('ComponentTwo') !== -1 // found





                      share|improve this answer















                      Check in the array using indexOf:



                      collectionOfComponents.indexOf('ComponentTwo') !== -1 // found






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Nov 12 '18 at 21:25

























                      answered Nov 12 '18 at 21:15









                      Bhojendra RauniyarBhojendra Rauniyar

                      50.9k2079125




                      50.9k2079125












                      • Components will not be unique there could be 5 ComponentOne and two ComponentTwo or there could be 7ComponentTwo and 1 ComponentOne

                        – zeduke
                        Nov 12 '18 at 21:22











                      • Anyways, you are just wondering if that component is found, right?

                        – Bhojendra Rauniyar
                        Nov 12 '18 at 21:24











                      • correct if a certain component exists in the array

                        – zeduke
                        Nov 12 '18 at 21:25











                      • Let me know if you have any query.

                        – Bhojendra Rauniyar
                        Nov 12 '18 at 21:25

















                      • Components will not be unique there could be 5 ComponentOne and two ComponentTwo or there could be 7ComponentTwo and 1 ComponentOne

                        – zeduke
                        Nov 12 '18 at 21:22











                      • Anyways, you are just wondering if that component is found, right?

                        – Bhojendra Rauniyar
                        Nov 12 '18 at 21:24











                      • correct if a certain component exists in the array

                        – zeduke
                        Nov 12 '18 at 21:25











                      • Let me know if you have any query.

                        – Bhojendra Rauniyar
                        Nov 12 '18 at 21:25
















                      Components will not be unique there could be 5 ComponentOne and two ComponentTwo or there could be 7ComponentTwo and 1 ComponentOne

                      – zeduke
                      Nov 12 '18 at 21:22





                      Components will not be unique there could be 5 ComponentOne and two ComponentTwo or there could be 7ComponentTwo and 1 ComponentOne

                      – zeduke
                      Nov 12 '18 at 21:22













                      Anyways, you are just wondering if that component is found, right?

                      – Bhojendra Rauniyar
                      Nov 12 '18 at 21:24





                      Anyways, you are just wondering if that component is found, right?

                      – Bhojendra Rauniyar
                      Nov 12 '18 at 21:24













                      correct if a certain component exists in the array

                      – zeduke
                      Nov 12 '18 at 21:25





                      correct if a certain component exists in the array

                      – zeduke
                      Nov 12 '18 at 21:25













                      Let me know if you have any query.

                      – Bhojendra Rauniyar
                      Nov 12 '18 at 21:25





                      Let me know if you have any query.

                      – Bhojendra Rauniyar
                      Nov 12 '18 at 21:25











                      -1














                      Maybe you can use this way or simulary ??



                       <Wrapper1>
                      {collectionOfComponents.map((oneComponent, index) => (
                      <Wrapper2
                      ..props
                      >
                      oneComponent.component instanceof ComponentTwo ? renderWasYouWant : otherRender
                      </Wrapper2>
                      )
                      </Wrapper1>





                      share|improve this answer





























                        -1














                        Maybe you can use this way or simulary ??



                         <Wrapper1>
                        {collectionOfComponents.map((oneComponent, index) => (
                        <Wrapper2
                        ..props
                        >
                        oneComponent.component instanceof ComponentTwo ? renderWasYouWant : otherRender
                        </Wrapper2>
                        )
                        </Wrapper1>





                        share|improve this answer



























                          -1












                          -1








                          -1







                          Maybe you can use this way or simulary ??



                           <Wrapper1>
                          {collectionOfComponents.map((oneComponent, index) => (
                          <Wrapper2
                          ..props
                          >
                          oneComponent.component instanceof ComponentTwo ? renderWasYouWant : otherRender
                          </Wrapper2>
                          )
                          </Wrapper1>





                          share|improve this answer















                          Maybe you can use this way or simulary ??



                           <Wrapper1>
                          {collectionOfComponents.map((oneComponent, index) => (
                          <Wrapper2
                          ..props
                          >
                          oneComponent.component instanceof ComponentTwo ? renderWasYouWant : otherRender
                          </Wrapper2>
                          )
                          </Wrapper1>






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 12 '18 at 21:54

























                          answered Nov 12 '18 at 21:47









                          A.VincentA.Vincent

                          487




                          487



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270111%2fhow-to-identify-component-name-from-a-object-array%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Kleinkühnau

                              Makov (Slowakei)

                              Deutsches Schauspielhaus