// initialization
const updateName = (value) => axios.post(`/budgets/${budgetId}/rename`, {name: value});
const budgetName = createUpdatable(getBudgetName(state), updateName);
// display
function BudgetName(props: { budgetName: Updatable.Updatable<string> }) {
const budgetName = props.budgetName;
const className = Updatable.State[budgetName.state()].toLowerCase();
return <span className={"budget-name " + className}>
<Switch>
<Match when={budgetName.error}>
<span>Error: {budgetName.error}</span>
</Match>
<Match when={budgetName.value()}>
<div>{budgetName.value()}</div>
</Match>
</Switch>
</span>;
}
// update
function UpdateBudgetName(props: UpdateBudgetNameProps) {
const budgetName = props.budgetName;
const submitUpdate = () => {
budgetName.setValue(inputElement.value);
return true;
};
// call submitUpdate somewhere in some input hander
// initialization
const updateName = (value) => axios.post(`/budgets/${budgetId}/rename`, {name: value});
const budgetName = createUpdatable(getBudgetName(state), updateName);
// display
function BudgetName(props: { budgetName: Updatable.Updatable<string> }) {
const budgetName = props.budgetName;
const className = Updatable.State[budgetName.state()].toLowerCase();
return <span className={"budget-name " + className}>
<Switch>
<Match when={budgetName.error}>
<span>Error: {budgetName.error}</span>
</Match>
<Match when={budgetName.value()}>
<div>{budgetName.value()}</div>
</Match>
</Switch>
</span>;
}
// update
function UpdateBudgetName(props: UpdateBudgetNameProps) {
const budgetName = props.budgetName;
const submitUpdate = () => {
budgetName.setValue(inputElement.value);
return true;
};
// call submitUpdate somewhere in some input hander