0

I’m still experimenting with react architecture in order to build my framework. So bare in mind that I’m kind of new to all these concepts.

I have a part of my code where I created two class based components:

<LayoutFrontendMain>
</LayoutFrontendMain>
And 
<FrontendCategoriesListing>
</FrontendCategoriesListing>

Next, I managed to display the FrontendCategoriesListing component in the right place of the LayoutFrontendMain component, passing the component as props, like so:

<LayoutFrontendMain cphBody={<FrontendCategoriesListing />}>

</LayoutFrontendMain>

So far, so good. The content of FrontendCategoriesListing is appearing in the right place of the LayoutFrontendMain component, just as I wanted.

The problem is that I have a very simple method (for now), in LayoutFrontendMain that changes state in itself. Something like so:

LayoutFrontendMain:

changeState()
{
     this.setState({
        titleCurrent: "new current title"
    });
}

Can I access this method and change the state in the component with the component I passed as a prop? Preferably, passing a string to change the state. Couldn’t find an example like this, anywhere.

Jorge Mauricio
  • 411
  • 6
  • 18
  • Ok first of all, your filter function is not returning anything on each iteration, which is a general issue. Every filter function must always return TRUE or FALSE in it's body (on every iteration). Secondly, your issues are related to "arrIdsCategoriesFiltersGeneric1Binding", but this variable is defined in the class, e.g. to access it, you need to refer to it with "this." infront =>. this.arrIdsCategoriesFiltersGeneric1Binding should do the job! – Todor Popov May 28 '20 at 13:09
  • Hi Todor. The logic wasn´t complete. I was still working on it, but thanks. The main focus was on the arrIdsCategoriesFiltersGeneric1Binding, but you identified the problem. I didn´t notice at all. Thanks a lot. – Jorge Mauricio May 29 '20 at 14:08
  • Todor - maybe there´s something else to it. This part, is defenitly wrong: return obj.id == arrIdsCategoriesFiltersGeneric1Binding[countArray]; But the part that was generating the error was on this part this.objCategoriesFiltersGeneric1Binding_print = this.ofglRecords.resultsFiltersGenericListing.filter(function(obj) { - and at that line, I´m using this. for context. Any ideas? – Jorge Mauricio May 29 '20 at 14:13

0 Answers0