Skip to content

Commit 768f242

Browse files
committed
Replace all jsx codeblocks with tsx
1 parent 26f9321 commit 768f242

21 files changed

+74
-79
lines changed

articles/Array-fields.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ If you have an array field with a constant size, you should probably just use [`
1313

1414
✔️ **Dynamic string array field using `ArrayForm`**
1515

16-
```jsx
16+
```tsx
1717
function NotesList() {
1818
const form = useForm({
1919
notes: ["Do the dishes", "Go outside", "Drink some water"],
@@ -56,7 +56,7 @@ function NotesList() {
5656

5757
Remember: this is all type checked!
5858

59-
```jsx
59+
```tsx
6060
function ShoppingListForm() {
6161
const form = useForm({
6262
title: "My shopping list",
@@ -113,7 +113,7 @@ function ShoppingListForm() {
113113

114114
✔️ **Dynamic object array field with seperate component for each child form and using `useArrayForm`**
115115

116-
```jsx
116+
```tsx
117117
interface ShoppingListItem {
118118
name: string;
119119
amount: number;
@@ -161,7 +161,7 @@ function ShoppingListItemsForm(props: { parent: FormState<ShoppingList> }) {
161161
);
162162
}
163163

164-
function ShoppingListItemForm(props: { parent: FormState<ShoppingListItem[]>, index: number, remove: (i: number) => void }) {
164+
function ShoppingListItemForm(props: { parent: FormState<ShoppingListItem[]>; index: number; remove: (i: number) => void }) {
165165
const form = useChildForm(props.parent, props.index);
166166
return (
167167
<div>
@@ -181,7 +181,7 @@ A fixed array always has the same size, [`ChildForm`](/docs/ChildForm) is used,
181181

182182
✔️ **Fixed array field containing strings**
183183

184-
```jsx
184+
```tsx
185185
function AnswerForm() {
186186
const form = useForm({
187187
// Always 3 items in array
@@ -216,7 +216,7 @@ function AnswerForm() {
216216

217217
✔️ **Fixed array field containing objects**
218218

219-
```jsx
219+
```tsx
220220
function SettingsForm() {
221221
const form = useForm({
222222
settings: [

articles/Auto-disable-submit-button.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![live updating form values](https://raw.githubusercontent.com/wiki/CodeStix/typed-react-form/images/submitbutton.gif)
44

5-
```jsx
5+
```tsx
66
function FormExample() {
77
const form = useForm(
88
{

articles/Custom-input.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ If the default input types (FormInput, FormSelect ...) do not provide enough fun
66

77
The following code resembles a custom input component that shows an error when needed, paints gray background when modified, gets disabled when submitting and shows its defaultValue as a placeholder. You can tweak this custom input further by implementing transformations for different input types, allowing `HTMLInputAttributes` etc.
88

9-
```jsx
9+
```tsx
1010
function CustomInput<T>(props: { form: FormState<T>; name: keyof T; children?: React.ReactNode }) {
1111
const { value, error, dirty, setValue, state, defaultValue } = useListener(props.form, props.name);
1212

@@ -30,7 +30,7 @@ function ExampleForm() {
3030
const form = useForm(
3131
{
3232
firstName: "John",
33-
lastName: "Pineapple"
33+
lastName: "Pineapple",
3434
},
3535
(values) => ({ firstName: values.firstName.length < 3 ? "Firstname must be longer!" : undefined }) // Example validator
3636
);
@@ -43,8 +43,7 @@ function ExampleForm() {
4343
if (form.error) return;
4444
form.setState({ isSubmitting: true });
4545
console.log("submit", form.values);
46-
}}
47-
>
46+
}}>
4847
<CustomInput form={form} name="firstName" />
4948
<CustomInput form={form} name="lastName" />
5049
<button>Submit</button>

articles/FormError.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A very simple field error component.
44

5-
```jsx
5+
```tsx
66
const form = useForm(
77
{
88
name: "John Tester"
@@ -22,24 +22,18 @@ Because this component doesn't have a lot of functionality (only props are `form
2222

2323
Below is an example of a custom form error component.
2424

25-
```jsx
26-
25+
```tsx
2726
// Use generics to create type-safe code
2827
function CustomFormError<T>(props: { form: FormState<T>; name: keyof T }) {
29-
3028
// Listen for changes on a form field, behaves like useState
3129
const { error } = useListener(props.form, props.name);
3230

3331
// Render nothing when no error
34-
if (!error)
35-
return null;
32+
if (!error) return null;
3633

3734
// Render a styled span on error.
38-
return <span style={{ color: "red", fontWeight: "bold" }}>
39-
{error}
40-
</span>;
35+
return <span style={{ color: "red", fontWeight: "bold" }}>{error}</span>;
4136
}
42-
4337
```
4438

4539
You can also create custom input components, look [here](/docs/Custom-inputs).

articles/FormInput.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ It is allowed to use multiple inputs on the same field, all of them will be sync
1414

1515
## Examples
1616

17-
```jsx
17+
```tsx
1818
const form = useForm({
1919
name: "codestix",
2020
age: 19,
@@ -47,7 +47,7 @@ const form = useForm({
4747

4848
Radio buttons must be given a value, and can be used for fields of different types.
4949

50-
```jsx
50+
```tsx
5151

5252
// Enum field
5353
<FormInput form={form} type="radio" name="gender" value="male" />
@@ -62,7 +62,7 @@ Radio buttons must be given a value, and can be used for fields of different typ
6262

6363
Checkboxes behave like a boolean field by default, but when given a value, it behaves as a primitive array field (like a select with multiple = true). They can also set values on check/uncheck, this is useful for toggling fields.
6464

65-
```jsx
65+
```tsx
6666
// Boolean field
6767
<FormInput form={form} type="checkbox" name="likePasta" />
6868

@@ -85,10 +85,10 @@ Checkboxes behave like a boolean field by default, but when given a value, it be
8585

8686
You **cannot** use FormInput to create a submit button (type="submit"). Use one of the following alternatives:
8787

88-
- ```jsx
88+
- ```tsx
8989
<input type="submit" value="Click here to submit" />
9090
```
91-
- ```jsx
91+
- ```tsx
9292
<button>Click here to submit</button>
9393
```
9494

articles/FormSelect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A stateful, type-checked form `select` element.
44

55
These inputs are given a `className` when errored (`typed-form-error`) or modified (`typed-form-dirty`) by default.
66

7-
```jsx
7+
```tsx
88
const form = useForm({
99
language: "english",
1010
visitedCountries: ["sweden"]

articles/FormTextArea.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A stateful, type-checked form `textarea` element.
44

55
These inputs are given a `className` when errored (`typed-form-error`) or modified (`typed-form-dirty`) by default.
66

7-
```jsx
7+
```tsx
88
const form = useForm({
99
description: "Ullamco velit eiusmod eiusmod veniam nulla exercitation fugiat.",
1010
});

articles/Getting-started.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ All of the form hook ([`useForm`](/docs/useForm), [`useChildForm`](/docs/useChil
2323

2424
✔️ **Importing and using `useForm`**
2525

26-
```jsx
26+
```tsx
2727
import { useForm } from "typed-react-form";
2828

2929
function MyForm() {
@@ -38,7 +38,7 @@ function MyForm() {
3838

3939
✔️ **`<form>` element with `onSubmit` event**
4040

41-
```jsx
41+
```tsx
4242
import { useForm } from "typed-react-form";
4343

4444
function MyForm() {
@@ -78,7 +78,7 @@ You are now ready to create inputs, this library provides the following built-in
7878

7979
✔️ **Example type-checked form consisting of 2 fields**
8080

81-
```jsx
81+
```tsx
8282
// Import FormInput
8383
import { useForm, FormInput } from "typed-react-form";
8484

articles/Live-json-component.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![live updating form values](https://raw.githubusercontent.com/wiki/CodeStix/typed-react-form/images/jsoncomponent.gif)
44

5-
```jsx
5+
```tsx
66
// Take a form containing any values
77
function FormJson(props: { form: FormState<any> }) {
88
// Listen for all changes on the form

articles/Object-fields.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This design choice makes complete type checking possible.
1111

1212
✔️ **Object field using `ChildForm`**
1313

14-
```jsx
14+
```tsx
1515
function PersonForm() {
1616
// Info object contains email and age
1717
const form = useForm({
@@ -45,7 +45,7 @@ function PersonForm() {
4545

4646
**✔️ `useChildForm` without seperate component**
4747

48-
```jsx
48+
```tsx
4949
function PersonForm() {
5050
// Create root form
5151
const form = useForm({ name: "John", info: { email: "[email protected]", age: 20 } });
@@ -70,7 +70,7 @@ function PersonForm() {
7070

7171
**✔️ `useChildForm` with seperate component**
7272

73-
```jsx
73+
```tsx
7474
interface Person {
7575
name: string;
7676
info: PersonInfo;
@@ -117,7 +117,7 @@ function PersonInfoForm(props: { parent: FormState<Person> }) {
117117

118118
This is also possible with `ChildForm`.
119119

120-
```jsx
120+
```tsx
121121
function PersonForm() {
122122
// Create root form
123123
const form = useForm({

0 commit comments

Comments
 (0)