
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
question-form
Advanced tools
React component for adding exercise questions to webpages or blogs.
npm install --save question-form
questions (required): of type Array. The required format of the questions array is shown below.color (optional -> default - '#ddd'): of type String used on for the borders of the question container.Every question should be in form of objects with three keys: name (string), options (array) and answer (number) which is the index of the answer in the options array.
import React, { Component } from 'react'
import QuestionForm from 'question-form'
import 'question-form/dist/index.css'
const Page = () => {
const questions = [
{
name: 'What is React?',
options: [
"React is this",
"React is that",
"React is cool"
],
answer: 0
},
{
name: 'What is science?',
options: [
"Science is bad",
"Science is good",
"Science is wow"
],
answer: 2
},
]
return (
<QuestionForm questions={questions} color='rgb(0, 140, 255)'>
)
}
<QuestionForm questions={questions} color='rgb(0, 140, 255)'>
)
} Result:

Result:

And on selection:

answer: 0 signifies the first option in the first question is correct and answer: 2 signifies the last option in the second question is correct.
This component can be used in any framework that allows querying of markdown posts. The questions array would be added to the frontmatter of the markdown, and on querying, this component can be used with the questions property of the frontmatter assigned to the questions prop.
This example uses a Gatsby Blog.
In the post markdown file:
---
title: "Post title"
questions:
[
{
name: "What is React?",
options: ["React is this", "React is that", "React is cool"],
answer: 0,
},
...,
]
---
...
Wherever you query your post, you could add the following: (the query used here is as shown in gatsby-starter-blog)
import React from 'react'
import QuestionForm from 'question-form'
---
export default ({data}) => {
const {frontmatter: {title, questions}} = data.markdownRemark;
return (
<div>
<h1>{title}</h1>
// some stuffs here
<h2>Exercise questions</h2>
// ensure the questions property is not null
{questions && (
<QuestionForm questions={questions}>
)}
</div>
)
}
---
export const query = graphql`
query($slug: String!) {
markdownRemark(fields: { slug: { eq: $slug } }) {
fields {
slug
}
frontmatter {
title
questions {
name
options
answer
}
}
}
}
`
You can check a practical example on my blog in this post. You'll find it at the bottom of the post
Your contribution to this project would be highly appreciated. It could be a documentation issue, pull request, feature request, they are all welcome.
MIT © dillionmegida
FAQs
Add exercise questions to your projects or blogs
We found that question-form demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.