Skip to content

Commit 15d5acd

Browse files
authored
fix(react): add override to class component render() method (#13743)
1 parent ff08542 commit 15d5acd

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

packages/react/src/generators/component/component.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,23 @@ describe('component', () => {
107107
).toBeFalsy();
108108
});
109109

110+
describe('--classComponent', () => {
111+
it('should add the override keyword to the render() method', async () => {
112+
await componentGenerator(appTree, {
113+
name: 'hello',
114+
style: 'css',
115+
project: projectName,
116+
classComponent: true,
117+
});
118+
119+
const tsxFileContent = appTree.read(
120+
`libs/my-lib/src/lib/hello/hello.tsx/`,
121+
'utf-8'
122+
);
123+
expect(tsxFileContent).toMatch(/override\srender\(\)/);
124+
});
125+
});
126+
110127
describe('--export', () => {
111128
it('should add to index.ts barrel', async () => {
112129
await componentGenerator(appTree, {

packages/react/src/generators/component/files/__fileName__.tsx__tmpl__

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const Styled<%= className %> = styled.div`
3434
<% }%>
3535
<% if (classComponent) { %>
3636
export class <%= className %> extends Component<<%= className %>Props> {
37-
render() {
37+
override render() {
3838
return (
3939
<<%= wrapper %><%- extras %>>
4040
<%= styledModule === 'styled-jsx' ? `<style jsx>{\`div { color: pink; }\`}</style>` : `` %>

0 commit comments

Comments
 (0)