Call a state change for a different component

Hi. I want a button on one page to change the state of a different component. Can this be done by scripted as I can’t see that option under onclick action? (option to change a state in the existing page is there). The samples i have found have been this.setState but I would need something like [component_name].setState

Hi, you can do this several different ways. I would recommend you to set the embedded component’s state via Data slot. Then you can simply change the state index value in data slot anywhere in the app and the component state will update accordingly the value in state.

Another option is to use Interaction: In element -> Change content -> component to state but this may cause conflicts if you want to change the component state also inside the component.

Here’s a preview link for my example “app”:

How can I link to a component from another component? E.g I want to call a comment component unto a screen from within another component.

Is this possible within RS?

Could you open a bit what do you mean? In React any data or interactions are not visible for components unless you pass the data or functions into child component. In react Studio you can only pass data to child components via props (Data linkages).

Some generic functions (e.g. how to access data slots etc.) are also passed with ‘app’ object to every component but these are not editable.

Data slots in Studio are global variables so if you edit the Data slot on one component other components will render automatically if the data slot is used for something in other components (e.g. component’s visibility or just showing the value in text label).