1.0.0 • Published 4 years ago

xs-epanets v1.0.0

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

laputa-renderer

npm.io

习题渲染器(可提交答案)

安装

yarn

yarn add laputa-renderer

npm

npm i laputa-renderer

使用

关于习题的 mock 可查看:mock.ts

只展示

/**
 * 只渲染
 */
import React from 'react';
import Renderer from 'lapuata-renderer';

const App: React.SFC<{}> = () => (
  <div>
    <Renderer schemas={MOCK_SCHEMA} />
  </div>
);

可提交答案

/**
 * 可提交
 */
import React, { useCallback } from 'react';
import Renderer from 'laputa-renderer';
import { RenderRef, AnswerItemType } from 'laputa-renderer/dist/types';

const App: React.SFC<{}> = () => {

  const renderer = React.createRef<RenderRef>();

  const handleSubmit = useCallback((answers: AnswerItemType[]) => {
    console.log('answers:::', answers);
  }, []);

  return (
    <div>
      <Renderer
        renderer={renderer}
        schemas={MOCK_SCHEMA}
        onSubmit={handleSubmit}
      />
      <button onClick={() => renderer.current.submit()}>提交</button>
    </div>
  )
}

API

参数说明类型
renderer习题 form 的 ref,可用于触发提交答案Ref
schemas习题的 schema,用于渲染习题TaskTestSchema[]
onSubmit提交答案的回调Function(answers)