I was trying to clean up my react component by moving some of the functions outside of render and when I pass self
down into a function, it loses it’s scope and I get an error: The record field send can't be found.
. I suppose it needs a type in the handleSubmit
function but when I look at the reason-react interface file I can’t seem to find one (everything just references send(a,b,c)
).
Minimal example:
let handleSubmit = (self, event) => {
SF_Utils.preventDefault(event);
self.send(Submitted);
Js.log("submit");
};
let make = (children) => {
...component,
initialState: getInitialState,
reducer: (action, state) => ... },
render: self => {
<div className="sf-form-container">
(
ReasonReact.createDomElement(
"form",
~props={"className": "sf-form", "onSubmit": handleSubmit(self)},
children,
)
)
</div>
},
};
However, after much tinkering, I’ve discovered that passing in self.send
does work fine. ¯\_(ツ)_/¯
However, I would still like to pass down self if possible so that I can access self.state
for other use cases.