Change input after initial render
See original GitHub issueHi!
What’s the correct way to change input after initial render ?
Because componentProperties
only set input on the first render, but we cannot test subsequent input changes this way (which leads to subsequent calls to ngOnChanges
).
For now, this works :
component.fixture.componentInstance.myInput = 'stuff';
component.detectChanges();
But accessing fixture
is not recommended (https://testing-library.com/docs/angular-testing-library/api#fixture, and I agree with this), and since I do not consider testing dynamic input change is testing an implementation detail, I believe there’s should be another way, right ?
Edit: Maybe something like this :
// component is a RenderResult here
component.setComponentInputs({
myInput: 'value'
});
// And call detectChanges / ngOnChanges automatically
Also, thanks for this library it’s really usefull !
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
how to update input defaultvalue using useRef (after the initial ...
The defaultValue property only works for inicial rendering, that is the reason that your desired behavior works one time and then stops.
Read more >React onChange with input field & button | by Mahesh
We wanted the component to display the initial render data on load. If the user makes changes by editing then we want to...
Read more >How to set focus on an input field after rendering in ReactJS
Creating React Application: · Step 1: Create a React application using the following command: · Step 2: After creating your project folder i.e. ......
Read more >How to Use React to Set the Value of an Input | Pluralsight
Note that you can modify its default/initial values based on the functional requirement. This next example shows shows how to use a ...
Read more >How to Set Focus On Element After Rendering With React
Let's get started by getting a reference to the input using the useRef() React hook. To do this, we would first import useRef()...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
rerender
is taken from the other testing libraries, to keep the API consistent.We’ll first do that, and see what we can do about
ngOnChanges
afterwards.🎉 This issue has been resolved in version 9.4.0 🎉
The release is available on:
npm package (@latest dist-tag)
Your semantic-release bot 📦🚀