I am passing the form value to the myDoc component but it showing Object are not valid as a React child, I am Beginner in React Error: Objects are not valid as a React child (found: object with keys {}). If you meant to render a collection of children, use an array instead.
import React,{useState} from 'react'
import {
PDFDownloadLink,
Page,
Text,
View,
Document,
StyleSheet,
} from '@react-pdf/renderer'
const styles = StyleSheet.create({
page: {
flexDirection: 'row',
backgroundColor: '#E4E4E4',
},
section: {
margin: 10,
padding: 10,
flexGrow: 1,
},
})
MyDoc Component
const MyDoc = (name) => (
<Document>
<Page size="A4" style={styles.page}>
<View style={styles.section}>
<Text>{name}</Text>
</View>
<View style={styles.section}>
<Text>Section #2</Text>
</View>
</Page>
</Document>
)
Edit Component
const Edit = () => {
const [name, setName] = useState('')
const [email, setEmail] = useState('')
const [about, setAbout] = useState('')
return (
<div className="EditScreen">
<form>
<input
type="text"
value={name}
placeholder="Name"
onChange={(e) => setName(e.target.value)}
></input>
<br></br>
<input
type="text"
value={email}
placeholder="Name"
onChange={(e) => setEmail(e.target.value)}
></input>
<br></br>
<input
type="text"
value={about}
placeholder="Name"
onChange={(e) => setAbout(e.target.value)}
></input>
<br></br>
<button type="submit">Submit</button>
</form>
Passing Name prop here
<PDFDownloadLink document={<MyDoc name={name} />} fileName="somename.pdf">
{({ blob, url, loading, error }) =>
loading ? 'Loading document...' : 'Download now!'
}
</PDFDownloadLink>
</div>
)
}
export default Edit ```