I am working with react. First I had a component with state I created methods and all that. Now I want to convert it into stateless component. I have add the word function
before each method name.
This is my file:
import React, { Component } from "react";
const Form = ({ sumbitBtn, onSubmit, inputs, id }) => {
onSubmit() {
}
renderInputs() {
}
sendErrors(errors) {
}
return (
...
);
};
Now I have tried to do it two ways but neither of them worked for me.
Using regular expression
I used the each of the following commands.
:%s/\w+\(\w*\)/function &/g
:%s/\w+\(\w*\)/function \0/g
:%s/(\w+\(\w*\))/function \1/g
But unfortunately the names of methods are showing rather its showing like function &
, function \0
.
Using macros
Another idea that came into my mind was that I could use a macro. Which have steps but I was stuck in one of the step which is finding the next method using regular expression and jumping to it.
My question is that how can we do this using both of the ways.
Note: the above file is just example file. The original file contains line breaks, comments between the methods.
Note: I am using the vim extension on vscode.
The result I want to get is
import React, { Component } from "react";
const Form = ({ sumbitBtn, onSubmit, inputs, id }) => {
function onSubmit() {
}
function renderInputs() {
}
function sendErrors(errors) {
}
return (
...
);
};