I had 2 different files and combined it int one web page. At one.js file in contain the text input and at the second.js files I had confirm button. What I want is, the user filled the value in one.js files than click confirm button on second page, the text input will be read only.
one.js
<TextField
type="text"
name={'jobs'}
value=''
fullWidth
/>
second.js
<Button
variant="contained"
disabled={!this.state.valid || this.state.isDisabled }
>
Confirm
</Button>
So far, I knew how to do it if using a single .js file. So is it possible to do this if have 2 different files?
Thanks for the clue
What you are talking about is essentially a shared
statebetween components, which updates as soon as theButtoncomponent is pressed and defines the read-only property of theTextFieldcomponent. You need to use the respectivestateapproaches for class and functional components, since state changes need to trigger a rerender.The state should be defined in an encapsulating parent component. A possible implementation, using functional components and hooks, can be found below:
Parent.jsx
one.js (example without imports)
two.js (example without imports)
I would highly recommend reading the official documentation regarding state and lifecycle.